How to Display the Last Updated Date of an Article in WordPress (3 Different Methods)

Last updated on
Jun 23, 2020

When looking for an article on the internet, some people prefer the ones that are regularly updated. This makes sense enough. If an article is regularly updated, it means that the writer (or anyone that is responsible for the article) cares about the relevance of the article. If you have a WordPress site and regularly update the articles on your site to keep them relevant, you can display a little info about when did the last time the article is updated.

There are several ways to display the last updated date of an article in WordPress. The method can be vary depending on the theme you use. If you use a simple theme such as GoPress, you can edit the single.php file by adding some lines of PHP code. If this method doesn’t work, you can also try to add a new function to your theme.

Here are 3 different ways to display the last updated date of an article in WordPress.

Method 1: Edit the single.php file

You can use this method if you use a simple theme such as GoPress and default WordPress themes such as Twenty Nineteen, Twenty Seventeen, and Twenty Twenty. On those themes, the code to display the post meta (including the date) are on the single.php file. To display the last modification date, add the following code right below the get_the_date(); code.

$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
if ($u_modified_time >= $u_time + 86400) { 
echo " | Updated "; 
the_modified_time('F j, Y'); 
}

Here is the example of the code placement.

If you can’t find the get_the_date(); code on the single.php file, you can try to find it on a file such as as post-meta.php file or other files with the similar names.

Method 2: Add a new function to a theme

If you have tried the method 1 above but didn’t work, you can try to add a new function to your theme. To do so, login to your WordPress dashboard and go to Appearance -> Theme Editor (make sure to login as administrator). Click the functions.php file on the right panel to edit it.

Add the following code on the last line on the functions.php file and click the Update File button to apply the new change.

function show_last_modified_date( $content ) {
$original_time = get_the_time('U');
$modified_time = get_the_modified_time('U');
if ($modified_time >= $original_time + 86400) {
$updated_time = get_the_modified_time('h:i a');
$updated_day = get_the_modified_time('F j, Y');
$modified_content .= '<p class="last-modified"><span style="background-color: #FFFF00"><i>Last updated:</i></span> '. $updated_day . '</p>';
}
$modified_content .= $content;
return $modified_content;
}
add_filter( 'the_content', 'show_last_modified_date' );

Method 3: Create a custom single post layout

If the first two methods above didn’t work, you can create a custom single post layout to replace the default single post layout of your theme and add any element you like, including an element to display the last modification date of an article. Don’t worry, you can create a custom single post layout without coding. Some page builder plugins, including Elementor, come with a theme builder feature that allows you to create a custom single post layout using a visual editor.

When creating a custom single post using Elementor, there is an option to display the last updated date of an article as you can see on the screenshot below.

You can read this article to learn more about how to create a custom single post in WordPress using Elementor.

In addition to Elementor, tagDiv Composer also allows you to create a custom single post layout on your WordPress site without coding. When creating a custom single post using tagDiv Composer, you can also add an element that displays the last modification date of an article.

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

Editorial Staff

new

Got WordPress Knowledge?

Why not turning it into profit? Learn how to turn your WordPress knowledge into profit blogging. FREE!

Where should we send the template?

Thanks! Please check your inbox to confirm.