X

Add a “Last Modified” Column in WordPress

This is a shameless modification of the code shared in Scribu’s Custom Sortable Columns post, hacked to display a sortable “Last Modified” column in edit.php. This will only work in WP 3.1 or higher.

Code Snippet:

<?php
// Register the column
function modified_column_register( $columns ) {
	$columns&#91;'modified_list'&#93; = __( 'Modified', 'my-plugin' );
 
	return $columns;
}
add_filter( 'manage_edit-post_columns', 'modified_column_register' );

// Display the column content
function modified_column_display( $column_name, $post_id ) {
	if ( 'modified_list' != $column_name )
		return;
	echo the_modified_date();
}
add_action( 'manage_posts_custom_column', 'modified_column_display', 10, 2 );

// Register the column as sortable
function modified_column_register_sortable( $columns ) {
	$columns&#91;'modified_list'&#93; = 'modified_list';
 
	return $columns;
}
add_filter( 'manage_edit-post_sortable_columns', 'modified_column_register_sortable' );
?>

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!