Created
December 12, 2020 11:04
-
-
Save finalwebsites/815fb80149a535cd7fe6f17a2c79459f to your computer and use it in GitHub Desktop.
Add a modified date column to your posts & pages list in WordPress
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
<?php | |
// Register Modified Date Column for both posts & pages | |
function modified_column_register( $columns ) { | |
$columns['Modified'] = __( 'Modified Date', 'show_modified_date_in_admin_lists' ); | |
return $columns; | |
} | |
add_filter( 'manage_posts_columns', 'modified_column_register' ); | |
add_filter( 'manage_pages_columns', 'modified_column_register' ); | |
function modified_column_display( $column_name, $post_id ) { | |
switch ( $column_name ) { | |
case 'Modified': | |
global $post; | |
echo '<p class="mod-date">'; | |
echo '<em>'.get_the_modified_date().' '.get_the_modified_time().'</em><br />'; | |
echo '<small>' . esc_html__( 'by ', 'show_modified_date_in_admin_lists' ) . '<strong>'.get_the_modified_author().'<strong></small>'; | |
echo '</p>'; | |
break; // end all case breaks | |
} | |
} | |
add_action( 'manage_posts_custom_column', 'modified_column_display', 10, 2 ); | |
add_action( 'manage_pages_custom_column', 'modified_column_display', 10, 2 ); | |
function modified_column_register_sortable( $columns ) { | |
$columns['Modified'] = 'modified'; | |
return $columns; | |
} | |
add_filter( 'manage_edit-post_sortable_columns', 'modified_column_register_sortable' ); | |
add_filter( 'manage_edit-page_sortable_columns', 'modified_column_register_sortable' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment