How to Display the Last Updated Date of Your WP Posts/Pages

Last Updated on January 26, 2021 by BrodNeil

There are different methods to display the last updated date on your posts:

  • functions.php
  • Themes templates (like single.php, archive.php, and other templates)
  • WP plugin

Check out the full article at of my favorite WP tutorial sites: https://www.wpbeginner.com/wp-tutorials/display-the-last-updated-date-of-your-posts-in-wordpress/

In this post, we’ve decided to go for the first method above, and that is via the functions.php.

You will need to add this code to your themeā€™s functions.php:

function wpb_last_updated_date( $content ) {
$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
if ($u_modified_time >= $u_time + 86400) { 
$updated_date = get_the_modified_time('F jS, Y');
$updated_time = get_the_modified_time('h:i a'); 
$custom_content .= '<p class="last-updated">Last updated on '. $updated_date . ' at '. $updated_time .'</p>';  
} 
 
    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'wpb_last_updated_date' );

Add custom CSS to style the appearance. Use this CSS as your starting point:

.last-updated {
    font-size: small;
    text-transform: uppercase;
    background-color: #fffdd4;
} 

Source: https://www.wpbeginner.com/wp-tutorials/display-the-last-updated-date-of-your-posts-in-wordpress/

WP Plugin

If you prefer a WP plugin, you can use this plugin: WP Last Modified Info. Using this plugin is pretty straightforward.

Leave a Comment