Admin & Dashboard PHP Beginner

Add a Sortable “Last Modified” Column

Show when each post and page was last updated, and sort the list by it to find stale content.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 24 lines
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' );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

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.

How it works

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.

Things to watch

  • The sortable filters are per post type. To sort other types, add manage_edit-{post_type}_sortable_columns for each.
  • “Last modified by” comes from the _edit_last meta, which is only set when someone saves in wp-admin.

How to test it

Open Pages → All Pages and click the “Last modified” heading. The list should sort from oldest to newest change.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only