Show when each post and page was last updated, and sort the list by it to find stale content.
function nahnu_modified_column( array $columns ): array {
$columns['nahnu_modified'] = 'Last modified';
return $columns;
}
function nahnu_modified_column_value( string $column, int $post_id ): void {
if ( 'nahnu_modified' === $column ) {
printf(
'%s<br><small>by %s</small>',
esc_html( get_the_modified_date( get_option( 'date_format' ), $post_id ) ),
esc_html( get_the_modified_author() ?: '—' )
);
}
}
function nahnu_modified_sortable( array $columns ): array {
$columns['nahnu_modified'] = 'modified';
return $columns;
}
add_filter( 'manage_posts_columns', 'nahnu_modified_column' );
add_filter( 'manage_pages_columns', 'nahnu_modified_column' );
add_action( 'manage_posts_custom_column', 'nahnu_modified_column_value', 10, 2 );
add_action( 'manage_pages_custom_column', 'nahnu_modified_column_value', 10, 2 );
add_filter( 'manage_edit-post_sortable_columns', 'nahnu_modified_sortable' );
add_filter( 'manage_edit-page_sortable_columns', 'nahnu_modified_sortable' );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
The Date column shows when something was published, not when it was last changed. To find pages that haven’t been updated in years, or check who changed something recently, you need the modified date.
The column shows the modified date in your site’s date format and the user who last saved it. Making it sortable maps the column to WordPress’s built-in modified order, so clicking the heading sorts by it with no extra query code.
manage_edit-{post_type}_sortable_columns for each._edit_last meta, which is only set when someone saves in wp-admin.Open Pages → All Pages and click the “Last modified” heading. The list should sort from oldest to newest change.