Add a modified date in a wordpress post

Similar to my last post on how to add the author name in a wordpress post, here is one more trick for a multiuser blog. Sometimes, when you are managing website or blog, where multiple users can create or update posts, it is required to have an eye, who and when modified the post.

Some wordpress themes have this support inbuilt and some themes (like the default “Twenty-Eleven” theme or one of my current theme “Bridge” by Blank Themes) does not have this option.

This is what need to be done:

You will find a function, similar to bridge_posted_on() [replace bridge with your theme name] in your functions.php file. This function usually shows the Author name in the post. We will add a similar function below it. The function will look similar to the code below. You may need to do some modification according to the theme you are using.

function bridge_post_modified_on() {
printf( 'Last modified by <span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span> on %4$s',
get_author_posts_url( get_the_author_meta( 'ID' ) ),
sprintf( esc_attr__( 'View all posts by %s', 'bridge' ), get_the_author() ),
get_the_author(),
esc_attr( get_the_modified_date() )
);
}

 

Now, you will find a code similar to the code below, in your content-single.php file. This code brings the title of the blog with author and date info.

<header class="entry-header">
        <h1 class="entry-title"><?php the_title(); ?></h1>
        <div class="entry-meta">
             <?php bridge_posted_on(); ?>
        </div><!-- .entry-meta -->
</header>

Now, call the post_modified_on() function here, that you defined in the functions.php in the above step.

<div class="entry-meta">
    <?php bridge_posted_on(); ?> - <?php bridge_post_modified_on(); ?>
</div><!-- .entry-meta –>

This will show the date modified along with the post date like shown below:

Your Blog Title

Posted on June 14, 2012 by Subrat Pattnaik – Last modified by Another Author on August 8, 2012

You may also call the above function anywhere you want to show the modified date with the author info (like in a search page or archive list page).

Hope this helps.