How to Display when a Post was Last Updated in WordPress

If you work in a fast moving niche like WordPress, a post’s publish date has a big impact on its relevance.

Google understands this, and factors publish date into its ranking algorithm. It also displays the publish date in the SERPs, informing searchers as to how timely the post is.

Example Date in the SERPs

Of course, the older a post is, the fewer clicks you’ll get — for example, a WordPress article from pre-2012 is practically redundant.

Just because an article was written a while ago, however, doesn’t necessarily mean the information is bad. These days, many of us focus on creating evergreen content — content designed to stand the test of time.

Even if your content is as relevant today as the day it was published, Google searchers will still regard a two-year-old post with suspicion, though.

To get around this problem, many WordPress users will update their best content regularly. Sprucing up your older content will keep your visitors engaged, but, most importantly, it ensures the content is still relevant.

Unfortunately, WordPress won’t display that your content has been updated — not by default, at least.

Good news, though: it is possible – and all it takes is adding one tiny snippet to your theme’s functions.php file.

If you want to try your luck with an out-of-date plugin called WP Last Modified, you can…but I don’t recommend it (which is why I’m not even going to link to it). Adding the code snippet is simple and will never go out of date because it uses core WordPress functions. Just follow these easy instructions.

Display Last Modified Time in WordPress

To display your post’s last modified time at the top of your post, you’ll need to add a short code snippet to your theme’s functions.php file. Remember – you should always use a child theme to make these additions.

To do that, head to Appearance → Editor and select the functions.php file for your child theme (or go to your custom plugin if you’re using one). Then, just paste in this code snippet:

function display_last_updated_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 jS, Y');
$modified_content .= '<p class="last-modified">This post was last updated on '. $updated_day . ' at '. $updated_time .'</p>';
}

$modified_content .= $content;
return $modified_content;
}
add_filter( 'the_content', 'display_last_updated_date' );

Wondering what the code snippet actually does? All the code does is:

  • Get the original publish date
  • Compare the original publish date to the date you last modified the post
  • If the post was modified more than 24 hours (86,400 seconds) after it was published, then it tells your theme to display a message saying “This post was last updated on day at time

Here’s what that looks like on the front-end:

If you want to change your last modified message, you can edit the text in the code snippet. Just make sure to only change the text – don’t remove any apostrophes or quotation marks.

Similarly, you can add custom styling to your last modified date by using CSS to style the last-modified class.

And that’s all there is to it! While it’s not quite as simple as just installing and activating a plugin, it’s hard to break anything with this method.

Final Thoughts

Displaying the last update stamp can have a big impact on your website’s success: visitors will trust updated content more, and the search engines will update their records the next time your website is crawled. That means better rankings, more clicks, and more engagement.

With this in mind, if you regularly update your content, displaying when it was last modified really is a must!

Do you display last modified dates? Share your thoughts in the comments below!

Featured image courtesy of Dafne Cholet.

New Posts in your inbox

  1. Does Google understand your article is posted on may 13 and updated on june 18? I mean, if Google understands that your post is posted actually on June 18, you will be penalized for non original content if anyone after you copies your article, you will become the content thief actually. Do you happen to know how this plugin works in this aspect?

  2. Do you Know if it still updated to say to google the article was updated?
    I installed it and google still showing the create post date 🙁

  3. Hello Shaun,

    Thanks for this helpful post. I implemented the code to my Dazzling theme and it works without any trouble. I only would not like to have it displayed on certain pages such as the welcome page and image gallery. Is there a way to have this last updated text only displayed on blog posts and not on pages?

    BR,
    Ralph

  4. This is a great topic because a client of mine had an issue I asked them to add the last modified
    I think every blog and site in the world should have tagged the last updated or “last modified” should be added to all pages and posts.
    It does a great job of letting users know you have updated Evergreen content this is very important. Another thing I’ve learned by accident a developer mistakenly placed the posted on the date before the last modified date and the posted date showed up in the SERPS in Google.

    The posted date was placed on not just the blog pages but every page and because it was it was done backward we saw a drop of 100,000 users in one week.
    Also, ranking drops for very prominent keywords were very evident.

    Within 20 minutes of making sure the last modified was prior to the “posted on” date moreover removing the posted on date from pages switching them you last modified first on the blog.

    The returned back to the same or better keyword placements and received all and more of our traffic back. So my message is simple this is great to employ on your site but just make sure no matter what. Only last modified on pages make sure posted date is never above or appearing before the “posted on date” I personally recommend never placing the posted date on pages (it great on Posts) if you do have it on taxonomies that are not equivalent of a blog in the way they function I suggest using only “last modified date” it this includes, knowledge-based any other taxonomies other than the blog.

    sorry for. the very long post I thought people could benefit from this mistake and believe me. this is worth doing. Also if you are somebody is not comfortable going to your site via SSH or SFTP, GIT, CLI etc. of your developer do it for whatever reason you do not have a developer but still would like to add this code there is an easy way for you to add the code given above to your function.php file There is a simple copy and paste plug-in called “Code Snippets”. if you want a to have it done by a developer so it looks just how you want it. Look at the great developers Pagely endorses. I have to thank Pagely really for introducing me to My favorite Performance Foundry a company I have worked with a lot and not say enough good things about them. I’m sure they would be able to help you as well. SEO is difficult enough “Last modified” is a no-brainer you should add it to your site.

  5. I am not tecky but have a problem that I can’t figure out the answer to. I scheduled a repost of a recipe (several of them) and Google Analytics sent me a 404 warning about content not being found. I did not change the url of any of the posts, just changed the date from the original post date to a date in the future. How can you repost a post without getting all of these 404 warnings?

  6. Hy Thanks for sharing last updated post date for wordpress. Can you tell me, how i can show this result at the end orf content, in post.

  7. Sir, thanks for the article which is necessary for the bloggers, but I want my actual published date as well. Could you please suggest that tweak also in the code or the new code which carries both dates. Help will be really appreciable.

  8. This is a great post, thank you!

    I just have one question. What does the code look like when you just want to show last updated on blog posts, and not on pages?

    Thanks.

  9. Hi, great article but how I can modified this code to show Updare before… For example I have post and I ant to display that post is update before 3 minutes or something similar (of course depends on time…) Thanks!

  10. This is great and very useful I only have one problem now. This makes it h1 tag, is there a way to remove h1 tag from it ? tx