Home / Admin / Add a Last Modified Column
Duplicate Snippet

Embed Snippet on Your Site

Add a Last Modified Column

This snippets adds a sortable "Last Modified" column to the posts list in the admin.

<10
Code Preview
php
<?php
function wpcode_custom_modified_column_register( $columns ) {
	$columns['last_modified'] = __( 'Last Modified', 'wpcode' );
	return $columns;
}
add_filter( 'manage_edit-post_columns', 'wpcode_custom_modified_column_register' );
function wpcode_custom_modified_column_display( $column_name, $post_id ) {
	if ( 'last_modified' != $column_name )
		return;
	echo the_modified_date();
}
add_action( 'manage_posts_custom_column', 'wpcode_custom_modified_column_display', 10, 2 );
// Register the column as sortable
function wpcode_custom_modified_column_register_sortable( $columns ) {
	$columns['last_modified'] = 'last_modified';
	return $columns;
}
add_filter( 'manage_edit-post_sortable_columns', 'wpcode_custom_modified_column_register_sortable' );

Comments

Add a Comment