Search

How to Add Sortable Last Modified Date Column to “All Posts” Page in WordPress

Adding a sortable “Last Modified Date” column to your WordPress All Posts screen (Posts -> All Posts) can truly elevate your content management experience. Just like the publish date, having a last modified date displayed on published posts enhances transparency and assists in keeping track of updates and revisions.

Imagine effortlessly organizing your posts based on their latest modifications, all with a simple click. This feature not only streamlines your workflow but also ensures that your content remains up-to-date and easily accessible.

With this handy addition, authors and website administrators can efficiently prioritize their tasks, promptly identifying and attending to posts that require attention. Whether it’s making revisions or updating information, managing your content becomes a breeze. Plus, you can rest assured knowing that you won’t need to install any plugins that might potentially affect your website’s performance, our step-by-step tutorial will walk you through the process seamlessly!

Adding a Sortable Modified Date Column to All Posts Page

Integrate a Custom Code

Since we’re steering clear of plugins, another method involves integrating custom code to incorporate the last modified date column into the posts page. The simplest route is to add this code directly to the functions.php file of your currently active theme.

Begin the process by navigating to the Appearance → Theme File Editor from your WordPress admin dashboard. Select the functions.php file from the Theme File list and paste the following code at the bottom of the file.

Note: For block themes, locate the Theme File Editor in the Tools menu. It’s advisable to create a backup of your WordPress files, either through backup plugins or the built-in backup feature of your hosting service. Alternatively, you can opt for a safer method to add custom code to your website.

// Add Last Date Modified Column
function wpp_modified_columns($columns) {
    $new_columns = array();

    foreach ($columns as $key => $value) {
        $new_columns[$key] = $value;
        if ($key === 'date') {
            $new_columns['date_modified'] = 'Updated';
        }
    }

    return $new_columns;
}
add_filter('manage_edit-post_columns', 'wpp_modified_columns');

// Display Last Date Modified Value
function wpp_custom_column_content($column, $post_id) {
    if ($column === 'date_modified') {
        $post_modified = get_post_field('post_modified', $post_id);
        
        // Last Modified word, line break, last modified date 
        $formatted_date = date_i18n('Y/m/d \a\t g:i A', strtotime($post_modified));
        
        echo 'Last Modified<br>' . $formatted_date;
    }
}
add_action('manage_post_posts_custom_column', 'wpp_custom_column_content', 10, 2);

// Make Last Date Modified Column Sortable
function wpp_custom_sortable_columns($columns) {
    $columns['date_modified'] = 'post_modified';
    return $columns;
}
add_filter('manage_edit-post_sortable_columns', 'wpp_custom_sortable_columns');

Customizing the Column Header and Text

The code provided above will introduce a new last modified column labeled “Updated” right after the Date column on the all-posts page. You can customize the header by simply locating the designated line of code and replacing the “Updated” text with your preferred choice of wording.

$new_columns['date_modified'] = 'Updated';

Additionally, the provided code will generate the “Last Modified” text along with a line break before the date in the new column. You can easily adjust this by locating the specified line of code and substituting the text with your preferred choice.

echo 'Last Modified<br>' . $formatted_date;

Once your code is ready, click the Update File button to apply the changes.

Now, when you navigate to the all posts page, you’ll notice a new sortable Updated column positioned after the Date column, displaying the last modified date for each post.

The Bottom Line

By adding a sortable “Last Modified Date” column to your WordPress All Posts Page, you’ll find managing your WordPress site easier and more efficient. Our tutorial makes the process straightforward, so you can start improving your content management system right away!

This page may contain affiliate links, which help support our project. Read our affiliate disclosure.
Hendri Risman

Hendri Risman

Hendri is a WordPress expert and a writer staff at WPPagebuilders. He writes solutions on how to get things fixed in WordPress a lot. Mostly without involving a plugin.
Want to save yearly expense up to $219? why not?

Leave a Comment