cms


Create a sortable ‘Modified Date’ sortable column for posts and pages in wordpress admin area 7

2016-07-14: Post updated to support both pages and posts without redundant/useless code

Paste the following in the functions.php file of your theme:

// Register the column for modified date
function bf_post_modified_column_register( $columns ) {
    $columns['post_modified'] = __( 'Modified Date', 'mytextdomain' );
    return $columns;
}
add_filter( 'manage_edit-post_columns', 'bf_post_modified_column_register' );
add_filter( 'manage_edit-page_columns', 'bf_post_modified_column_register' );

// Display the modified date column content
function bf_post_modified_column_display( $column_name, $post_id ) {
    if ( 'post_modified' != $column_name ){
        return;
    }
    $post_modified = get_post_field('post_modified', $post_id);
    if ( !$post_modified ){
        $post_modified = '' . __( 'undefined', 'mytextdomain' ) . '';
    }
    echo $post_modified;
}
add_action( 'manage_posts_custom_column', 'bf_post_modified_column_display', 10, 2 );
add_action( 'manage_pages_custom_column', 'bf_post_modified_column_display', 10, 2 );

// Register the modified date column as sortable
function bf_post_modified_column_register_sortable( $columns ) {
    $columns['post_modified'] = 'post_modified';
    return $columns;
}
add_filter( 'manage_edit-post_sortable_columns', 'bf_post_modified_column_register_sortable' );
add_filter( 'manage_edit-page_sortable_columns', 'bf_post_modified_column_register_sortable' );

When you refresh http://<Your Domain>/wp-admin/edit.php or http://<Your Domain>/wp-admin/edit.php?post_type=page the ‘Modified Date’ column will be visible and sortable.


Include more filetypes to a WordPress Installation Media Library

In the folder <Installation Path>/wp-includes/ there is a file called functions.php, inside this file there is a function called get_allowed_mime_types().
This function is in charge of defining an Array of mime types keyed by the file extension with a regex corresponding to those types.

So in order to add a new file-type to the white-list you just have to add a new line with the following format in the list:

'jpg|jpeg|jpe' => 'image/jpeg',

Where, on the left you define the extensions you want to be accepted separated by the vertical bar character (“|”) and on the right you give a file definition.