| |

How to Add a Sortable “Last Updated” Column in WordPress Admin Posts List

If you’re managing a blog or website with regularly updated content, it’s helpful to quickly see when each post was last modified. By default, WordPress shows only the publish date in the admin panel, but you can easily add a “Last Updated” column and make it sortable with a few lines of code.

In this tutorial, I’ll show you how to add a Last Updated column in the Posts > All Posts screen of your WordPress admin dashboard.

💡 Don’t worry! This is beginner-friendly. You can copy and paste the code below into your theme’s functions.php file or use a code snippets plugin like Code Snippets to avoid editing theme files directly.

Step-by-Step Code to Add the “Last Updated” Column

1. Add the column to the Posts list

This function adds a new column titled “Last Updated” to the posts list in the WordPress admin.

function custom_add_last_updated_column( $columns ) {
    $columns['last_updated'] = 'Last Updated';
    return $columns;
}
add_filter( 'manage_posts_columns', 'custom_add_last_updated_column' );

2. Display the last modified date in the new column

Here, we populate the column with the modified date of each post using get_the_modified_date().

function custom_show_last_updated_column( $column_name, $post_id ) {
    if ( 'last_updated' === $column_name ) {
        echo esc_html( get_the_modified_date( 'M d, Y', $post_id ) );
    }
}
add_action( 'manage_posts_custom_column', 'custom_show_last_updated_column', 10, 2 );

3. Make the column sortable

We tell WordPress to allow sorting on this new column by mapping it to the post_modified field.

function custom_sortable_last_updated_column( $columns ) {
    $columns['last_updated'] = 'modified';
    return $columns;
}
add_filter( 'manage_edit-post_sortable_columns', 'custom_sortable_last_updated_column' );

4. Adjust the query to sort by the last modified date

This step makes the sorting actually work when you click the “Last Updated” column heading.

function custom_sort_last_updated_column( $query ) {
    if ( ! is_admin() || ! $query->is_main_query() ) {
        return;
    }

    if ( $query->get( 'orderby' ) === 'modified' ) {
        $query->set( 'orderby', 'modified' );
    }
}
add_action( 'pre_get_posts', 'custom_sort_last_updated_column' );

🔍 How It Works (In Simple Terms)

Let’s break it down:

  • manage_posts_columns: Adds a new column to the posts table.

  • manage_posts_custom_column: Fills that column with data (in this case, the last updated date).

  • manage_edit-post_sortable_columns: Lets WordPress know the column is sortable.

  • pre_get_posts: Modifies the admin query to sort based on the post_modified date when sorting is triggered.


✅ Final Result

After you add this code:

  • You’ll see a new column labeled “Last Updated” next to your post titles.

  • You can click on it to sort posts from the most recently updated to the oldest — and vice versa.


🛡️ Bonus Tips

  • Use a child theme or the Code Snippets plugin to keep changes safe during theme updates.

  • You can use the same technique for other post types like Pages or Custom Post Types — just replace manage_posts_columns with the corresponding hook (e.g., manage_page_columns).


🙋 Need Help?

If you’re new to adding code in WordPress or want help extending this to Pages or Custom Post Types, feel free to leave a comment or reach out!

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *