WordPress is being used for many purposes. Some are for blogs, whereas others are news sites. When you pubilsh a news story, there are often times you might need to make updates. In this tutorial we will share how you can let your users know that the post was updated. We will highlight how to display the last updated date of your posts.
For example, if you posted an article on July 19, 2009, and you found out three days later that there was an update to the story. You can just edit the article, and it will show July 22, 2009 at the timestamp for last update.
First you need to open these three files:
- index.php
- single.php
- page.php
Then you will need to locate the following code:
1 | <?php the_modified_time( 'F jS, Y' );?> |
Note: Since there are so many formats of displaying dates, you might not see the exact code, but something along this line.
Replace it with:
1 | <?php $u_time = get_the_time( 'U' ); |
2 | $u_modified_time = get_the_modified_time( 'U' ); |
3 | if ( $u_modified_time >= $u_time + 86400) { |
4 | echo "and last modified on " ; |
5 | the_modified_time( 'F jS, Y' ); |