Archived topic
Showing last updated date date of posts in admin panel
1 reply · Started by deba on January 5, 2022
Hi team,
Is there a way to show the last modified/updated date in the posts list in the admin panel? Maybe a filter or hook that can add another column showing the last updated date of each of the posts? I don't really want to install another plugin just for this feature if it can be achieved by some code/function.
Hi there,
This isn't something the theme controls as this is WordPress core backend UI.
While I understand that you'd want to avoid installing plugins for this, consider reviewing the codes used for really short plugins like this one - https://wordpress.org/plugins/show-modified-date-in-admin-lists/
This plugin basically has this code in it:
// 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' );
add_filter( 'manage_media_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 />';
if ( !empty( get_the_modified_author() ) ) {
echo '<small>' . esc_html__( 'by', 'show-modified-date-in-admin-lists' ) . ' <strong>'.get_the_modified_author().'<strong></small>';
} else {
echo '<small>' . esc_html__( 'by', 'show-modified-date-in-admin-lists' ) . ' <strong>' . esc_html__( 'UNKNOWN', 'show-modified-date-in-admin-lists' ) . '<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 );
add_action( 'manage_media_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' );
add_filter( 'manage_upload_sortable_columns', 'modified_column_register_sortable' );
Which hooks in the column for the post lists.