Display the last modified details of a post

How to display the last modified details of a WordPress post

When operating a website with multiple user accounts, it is handy to track the timing and identify the individuals who have made any modifications to the content. There are several compelling reasons why this information is important, however, it is primarily centred around accountability and security.

One key reason for tracking these changes is to hold responsible parties accountable in case a post update leads to a significant decline in search engine optimization (SEO) performance. By identifying the person responsible, appropriate measures can be taken, such as addressing the issue directly with them or providing additional training to prevent similar occurrences in the future.

Having access to this information also allows you to determine whether unauthorized user accounts have tampered with the content on a specific page. Such unauthorized modifications serve as a clear indicator that your WordPress website may have been compromised, prompting you to take immediate action to address the breach and reinforce security measures.

In this article, I am going to show you how to add the last modified information to the post and page tables of your admin panel without the use of a plugin. Although there are a number of plugins that can deliver similar functionality this can also be achieved through a few lines of code.

The following code will need to be placed either in your functions.php, a plugin or a code snippet plugin.

Step 01: Add a new column header

The following code will create a new admin column that will display the last modified details.

// Add column header
function gwa_modified_date_column_header($columns) {
    $columns['last_modified'] = 'Last Modified';
    return $columns;
}
add_filter('manage_posts_columns', 'gwa_modified_date_column_header');
add_filter('manage_pages_columns', 'gwa_modified_date_column_header');

The add_filter functions will add this column to both the post and page post types.

Step 02: Retrieve the last modified information and display it in the post row

The second snippet is responsible for populating the newly added admin column. Once again we are calling the add_action function twice to include the data on both the post and page post types. This code will display the date/time of the update and the user account that submitted the changes.

// Populate column with data
function gwa_modified_date_column_content($column_name, $post_id) {
    if ($column_name == 'last_modified') {
        // Check if the post or page has been modified
        if (get_the_modified_date('Ymd', $post_id) != get_the_date('Ymd', $post_id)) {
            // Display the last modified date and time
            $last_modified = get_the_modified_date('F j, Y g:i a', $post_id);
            
            // Get the user who made the last modification
            $last_modified_by = get_the_modified_author();
            
            // Display the last modified date, time, and user
            echo $last_modified . '<br>by ' . $last_modified_by;
        }
    }
}
add_action('manage_posts_custom_column', 'gwa_modified_date_column_content', 10, 2);
add_action('manage_pages_custom_column', 'gwa_modified_date_column_content', 10, 2);

Step 03: Save your code

Finally, we want to ensure that our new code has been saved. And that's it. Now you should see when and who made changes to each post and page on your WordPress site.

Last modified details in WordPress

Does this code still work?

WordPress is an ever-changing platform and sometimes updates will break custom functionality. If this code no longer works, let us know and we will update it.

Community Projects

Subscribe to our newsletter

The latest SevenDev news, articles sent straight to your inbox every month.
SevenDev - WordPress Growth Agency

Start generating more business today

Contact SevenDev to see what we can do for you!
SevenDev
Home
Powerful website dashboard
Services
Fully Managed Hosting
Website Design
Product Variations
eCommerce
Online Stores
WordPress Development
Full Site Development
Website Maintenance
WordPress Maintenance
Articles
WordPress Themes
Contact
Mobile Website Conversions
Close
facebooklinkedinangle-double-rightangle-downchevron-circle-leftyoutube-playinstagram