How To Display When A WordPress Post or Page Is Updated

I write and publish posts on this site using the WordPress publishing system and then often update them with new insights relevant to the posts and so in addition to displaying when posts and pages were original published, I thought it would be useful to also show when they were updated.

WordPress by default does not seem to do this and so, I wrote some custom PHP code to display when posts are updated next to when the post was published and have replicated the updated display for pages.

The method to display when posts and pages are updated takes the update date from the database table for posts and pages where the latest updated date is stored.

So here are the methods to display when Posts and Pages have been posted and updated.

The instructions below are based on using the Twenty Ten default WordPress theme, but if you use another theme as I do, I’m sure on will be able to use the instructions on your theme.

Posts:

Within the Twenty Ten theme I there are 2 instances in the code where the post publish date is displayed.

  1. On Archive, Category, and Search Pages which are displayed from the file loop.php in the theme directory.
  2. On Single full Posts, which are displayed from the file loop-single.php also in the theme directory.

In both files, search for the code <?php twentyten_posted_on(); ?> and replace it with the following code which will disable this code and add some new code:

<?php //twentyten_posted_on(); ?>
<?php
$postedon = get_the_date('F j, Y');
$postedupdated = get_the_modified_date('F j, Y');
echo "Posted on ".$postedon;
echo ($postedon == $postedupdated) ? '.' : ' and Updated on '.$postedupdated.'.';
?>

Pages:

Again, the following guide is specific to the Twenty Ten theme but there should not be too work involved in integrating page updates into your own theme. Edit the loop-page.php file in theme directory and add the code below after the code where the title is displayed and before where the content is displayed.

Note: by default a page does not show when it was published so I added the feature using the same code from posts that shows the published date and then added my code after it.

<div>
<?php
$postedon = get_the_date('F j, Y');
$postedupdated = get_the_modified_date('F j, Y');
echo "Posted on ".$postedon;
echo ($postedon == $postedupdated) ? '.' : ' and Updated on '.$postedupdated.'.';
?>
</div><!-- .entry-meta -->

Now upload the updated files loop.php, loop-single.php and loop-page.php to the theme directory on your site’s server and that should do the trick.

Displaying Recently Updated Posts On Your Sidebar:

With a recent version of WordPress you should be able to do this using the sidebar Widgets.

Share this:

Subscribe for updates

Enter your email address below. I’ll send you updates & news to your email address. You can unsubscribe at any time.


Posted

in

by

Tags:


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

>