Created
April 16, 2020 22:33
-
-
Save grayayer/6456d37d8cc58d32e10b93ce879117ef to your computer and use it in GitHub Desktop.
Add a “Last Modified” Column in WordPress for pages and posts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Add a “Last Modified” Column in WordPress for pages and posts **/ | |
// Register the column | |
function modified_column_register( $columns ) { | |
$columns['modified_list'] = __( 'Modified', 'my-plugin' ); | |
return $columns; | |
} | |
add_filter( 'manage_edit-page_columns', 'modified_column_register' ); | |
add_filter( 'manage_edit-post_columns', 'modified_column_register' ); | |
// Display the column content | |
function modified_column_display( $column_name, $post_id ) { | |
if ( 'modified_list' != $column_name ) | |
return; | |
echo the_modified_date(); | |
} | |
add_action( 'manage_pages_custom_column', 'modified_column_display', 10, 2 ); | |
add_action( 'manage_posts_custom_column', 'modified_column_display', 10, 2 ); | |
// Register the column as sortable | |
function modified_column_register_sortable( $columns ) { | |
$columns['modified_list'] = 'modified_list'; | |
return $columns; | |
} | |
add_filter( 'manage_edit-page_sortable_columns', 'modified_column_register_sortable' ); | |
add_filter( 'manage_edit-post_sortable_columns', 'modified_column_register_sortable' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment