// Add a column to the posts and pages list in the admin panel to display the last modified date function add_last_modified_column($columns) { $columns['last_modified'] = 'Last Modified'; return $columns; } add_filter('manage_posts_columns', 'add_last_modified_column'); add_filter('manage_pages_columns', 'add_last_modified_column'); // Populate the last modified column with the date and time function display_last_modified_column($column, $post_id) { if ($column == 'last_modified') { $last_modified = get_post_modified_time('F j, Y, g:i a', false, $post_id); echo $last_modified; } } add_action('manage_posts_custom_column', 'display_last_modified_column', 10, 2); add_action('manage_pages_custom_column', 'display_last_modified_column', 10, 2); // Make the last modified column sortable function make_last_modified_column_sortable($columns) { $columns['last_modified'] = 'last_modified'; return $columns; } add_filter('manage_edit-post_sortable_columns', 'make_last_modified_column_sortable'); add_filter('manage_edit-page_sortable_columns', 'make_last_modified_column_sortable'); // Set the sorting logic for the last modified column function sort_by_last_modified($vars) { if (isset($vars['orderby']) && 'last_modified' == $vars['orderby']) { $vars = array_merge($vars, array( 'orderby' => 'modified' )); } return $vars; } add_filter('request', 'sort_by_last_modified');
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter