Put last modified / last Updated date in WordPress

2 minutes read

You might have noticed that some WordPress blogs show a last modified or last updated date in place of the published date on the posts or pages. If you’re looking to add the same functionality to your blog too, this tutorial will going to help you to achieve that – we’ll see the both the DIY way and using plugins to accomplish that.

WordPress plugin to show last modified date

I’ve written a WordPress plugin called WP Last Modified that allows you to add last modifed date to your WordPress posts and pages in a controlled way. You may also add Revised meta tags to your WordPress posts and pages with it, but it’s completely optional.

WP Last Modified WordPress plugin »

Show Last modified date manually in WordPress

Note: Customizing your WordPress theme involves editing it’s different files which may need a little expertise with WordPress coding standard and development. It’s always better to backup your theme before editing. The recommended way to customize your theme is to do it locally (i.e. on a local WordPress installation rather than on your live site).

In order to show the modified date instead of the post published date, you need to edit some of your theme files. So, lets start, if you want to show the last updated date in your single (or full) post, just edit the single.php and look for the <?php the_date(); ?> or <?php get_the_date(); >.

If you’re not able to find the two functions, look for the template that has been called in the file to execute the loop. Try to figure out where these two functions are executing and replace it with the below code:

<?php the_modified_date('l, F j, Y', '<div class="the-modified-date">', '</div>'); >

The first parameter (highlighted in red) in the above function is the format of our date. That value there will display our date in this fashion: Sunday, May 12, 2013. Read more about Formatting WordPress date and time.

Value of the next parameter (highlighted in green) would be text or markup that should appear in the starting of our date. In the example code, I’ve added an opened HTML division tag since I wanted to put the date in a division.

Similarly, the next parameter (highlighted in blue) will carry value that should appear after the date. I’ve added a closing HTML div since I’ve placed and opened div tag in the start of the date. Check out the output I obtained by making the changes.

Result of the_modified_date() in WordPress

If you don’t want to show anything before or after the date, leave the parameters blank. Feeling confused? Read more about the_modifed_date function at WordPress codex.

You may repeat the process for the files page.php to show the modified date on pages.

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

Related Posts:

To get yesterday&#39;s date in MySQL, you can use the DATE_SUB() function. This function subtracts a specified time interval from a date.The syntax of the DATE_SUB() function is as follows: DATE_SUB(date, INTERVAL value unit) Here, date is the current date, an...
To change a date format in MySQL, you can use the DATE_FORMAT() function. The syntax of the function is as follows: DATE_FORMAT(date, format) The date parameter represents the date column or value that you want to format, and the format parameter specifies the...
To remove the last subcategory name from WooCommerce breadcrumbs, you can use the &#39;woocommerce_breadcrumb&#39; filter hook. You can create a custom function that removes the last item from the breadcrumbs array before it is displayed on the front end. This...