WordPress is a powerful content management system. The implementation of WordPress is wider that you probably thought. From personal blog to a complex news portal. If you have a WordPress-based site and regularly update your articles to keep them relevant, you probably want to display an information when was your articles last updated.
Displaying the last updated date of an article in WordPress is not too hard, but it can also a bit tricky especially if you have no PHP skill. There are several methods to do it. Whether using a plugin, adding new code on the theme’s functions.php
file or by editing your theme. In this post, I will show you how to display the last updated date of posts in WordPress using the last option.
I have actually tried all three methods above, but I think editing the theme is the easiest way and works on nearly all WordPress themes.
The part of the theme you need to edit is not the same on every theme. You need to look for the code responsible for displaying post meta (date, author, category).
On most themes, the code can be found on the single.php
file, but not always. In my case, the code is on the post-meta.php
file. The file of post-meta.php
is located under the “functions” directory on the structure directory of the theme I use. So, in this case, the theme part I need to edit is post-meta.php
.
Then, as I mentioned, I need to look for the code responsible for displaying the date.
Then, you can add the following code right after the code above.
$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'); }
Or, if you wish it, you can also replace the code responsible for displaying the date. I prefer to retain it. Below is the result of the steps above.
.