How to Add Updated Date to WordPress Articles

By Posted 2013 Updated   BloggingSEOTutorialsWordPress

It is a good idea to add updated post date and time to your WordPress posts to let search engines know when your post was updated. As search engines have started giving higher search engine rankings to  recently posted articles or updated content, it is essential to post updated dates.

Structured Data Errors

We analysed the new structured data reports in Google webmaster tools and saw thousands of errors on all posts and pages. When we tested the rich snippet testing tool, there were no errors.

structureddataerror

The errors were caused by missing updated class in the hatom microdata.

missing updated errors

If you read the hentry guidelines, you find that updated is a required field (not the published date!). In fact only entry-title and updated are required 2 classes, rest are all optional. So it is a great idea to add updated classes to your post.

If you remember, we had added both the published and updated dates for quite some time, but then Google ignores the updated date. So maybe it is a better idea to only show updated dates.

Display Updated Date

While we discussed how to add updated date by direct php code insertion in the post, when I checked my Twenty Fourteen WordPress theme, it was not so easy to edit it.

Since we use a child theme (which you should always do for any theme), we needed to add some code to the functions.php file to edit the post meta information.

If you check the content.php file in your theme, the particular code twentyfourteen_posted_on  outputs the post meta, and is located in the template-tags.php. The detailed code looks like this

if ( ! function_exists( 'twentyfourteen_posted_on' ) ) :
/**
* Print HTML with meta information for the current post-date/time and author.
*
* @since Twenty Fourteen 1.0
*
* @return void
*/
function twentyfourteen_posted_on() {
if ( is_sticky() && is_home() && ! is_paged() ) {
echo '<span class="featured-post">' . __( 'Sticky', 'twentyfourteen' ) . '</span>';
}

// Set up and print post meta information.
printf( '<span class="entry-date"><a href="%1$s" rel="bookmark"><time class="entry-date" datetime="%2$s">%3$s</time></a></span> <span class="byline"><span class="author vcard"><a class="url fn n" href="%4$s" rel="author">%5$s</a></span></span>',
esc_url( get_permalink() ),
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
get_the_author()
);
}
endif;

Here are the changes we will make to this code and then add to the child themes functions.php file. Remember to keep a back up of this file as any error will need the original to be replaced via FTP.

  1. Show Updated Date – So we will edit this to replace the get_the_date with get_the_modified_date code. This will serve the updated date instead of the published date.
  2. Updated Class – Add the updated class to the date so that the hentry microdata becomes valid and the structured data errors are gone.
  3. Show Updated Text –  it is a good idea to show updated text besides the date to let readers know that this is the updated date and not the original post published date. You do not want people to find 5 year old comments in a post which shows a month old date.

So here is the same code we have modified *changes seen in bold and underline). You can check this live on our site now.

if ( ! function_exists( 'twentyfourteen_posted_on' ) ) :
/**
* Print HTML with meta information for the current post-date/time and author.
*
* @since Twenty Fourteen 1.0
*
* @return void
*/
function twentyfourteen_posted_on() {
if ( is_sticky() && is_home() && ! is_paged() ) {
echo '<span class="featured-post">' . __( 'Sticky', 'twentyfourteen' ) . '</span>';
}

// Set up and print post meta information.
printf( 'UPDATED <span class="entry-date updated"><a href="%1$s" rel="bookmark"><time class="entry-date updated" datetime="%2$s">%3$s</time></a></span> <span class="byline"><span class="author vcard"><a class="url fn n" href="%4$s" rel="author">%5$s</a></span></span>',
esc_url( get_permalink() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() ),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
get_the_author()
);
}
endif;

NOTE: Please do these changes at your own risk. We take no responsibility of how this will affect your site rankings  in search engine results.


29 comments on “How to Add Updated Date to WordPress Articles

  1. Madhav Tripathi says:

    My website has zero hatom markups, I think there were some markups of this kind.

  2. Per Soderlind says:

    Nice article, used it to create this function for the twentytwelve theme (add it to functions.php in the child theme):

    
    function twentytwelve_entry_meta() {
    	// Translators: used between list items, there is a space after the comma.
    	$categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
    
    	// Translators: used between list items, there is a space after the comma.
    	$tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );
    
    	$is_updated_post = (get_the_modified_date( 'U' ) > get_the_date( 'U' ));
    	if ( $is_updated_post ) {
    		$date = sprintf( '%4$s',
    			esc_url( get_permalink() ),
    			esc_attr( get_the_modified_date() ),
    			esc_attr( get_the_modified_date( 'c' ) ),
    			esc_html( get_the_modified_date() )
    		);
    	} else {
    		$date = sprintf( '%4$s',
    			esc_url( get_permalink() ),
    			esc_attr( get_the_time() ),
    			esc_attr( get_the_date( 'c' ) ),
    			esc_html( get_the_date() )
    		);
    	}
    
    
    	$author = sprintf( '%3$s',
    		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    		esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
    		get_the_author()
    	);
    
    	// Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name.
    	if ( $tag_list ) {
    		if ($is_updated_post) { 
    			$utility_text = __( 'This entry in %1$s and tagged %2$s was updated on %3$s by %4$s.', 'twentytwelve' );
    		} else {
    			$utility_text = __( 'This entry was posted in %1$s and tagged %2$s on %3$s by %4$s.', 'twentytwelve' );
    		}
    	} elseif ( $categories_list ) {
    		if ($is_updated_post) {
    			$utility_text = __( 'This entry in %1$s was updated on %3$s by %4$s.', 'twentytwelve' );
    		} else {
    			$utility_text = __( 'This entry was posted in %1$s on %3$s by %4$s.', 'twentytwelve' );
    		}
    	} else {
    		if ($is_updated_post) {
    			$utility_text = __( 'This entry was updated on %3$s by %4$s.', 'twentytwelve' );
    		} else {
    			$utility_text = __( 'This entry was posted on %3$s by %4$s.', 'twentytwelve' );
    		}
    	}
    
    	printf(
    		$utility_text,
    		$categories_list,
    		$tag_list,
    		$date,
    		$author
    	);
    }
    
  3. Clay Morisson says:

    Useful info! I had no idea about this before, thanks a lot.

  4. fenny says:

    thank you for sharing this lesson, i just want make some wordpress

  5. Web Consultant says:

    Nice thing but we need to be very careful while doing it as any manual error can lead to a catastrophe.

  6. Nancy Badillo says:

    Hi,
    I was not aware you can update the date in WordPress. Thanks for sharing this cool post. I look forward in doing the change myself.

  7. Souri says:

    Great idea. Would love an update date on some blog posts without removing the original post date. Haha … too complicated for me … I wait until it comes out of the box to WordPress …

  8. Shital Bhalani says:

    Why not just use Isn’t it a lot easier as a built in function where you can change the display type in Settings > General ??
    suggest me if i am wrong.

    -Shital

    • P. Chandra says:

      This article is about adding the updated date. The settings advise date format and themes usually print published dates.

  9. Priyanka Jain says:

    This is terrific. i was really puzzled about updating the dates of the posts but was unable to sort out. thanks. would try out now.

  10. BestofBacklinks says:

    Nice! Since search engines want us to be updating our content as much as possible then the date issue on posts really makes sense. I have surely liked your article.
    Great ideas.

  11. Deep says:

    This article is very useful. I am searching this type of post. Thanks for the info.

  12. Technology Blog and Tutorial says:

    I was confused before to add updated on my site. thanks for sharing this post. see my site. You can to post on my site http://www.graphicalarm.com

  13. PR Agency San Francisco says:

    Hi,

    Thanks for sharing this post, i was looking for such a post to understand how to update dates & time in wordpress…

  14. sharma says:

    Nice! Since search engines want us to be updating our content as much as possible then the date issue on posts really makes sense. I have surely liked your article.
    Great ideas.

  15. Pradeepkumar V D says:

    I tried this code, but the lines of the code are somehow displayed over the navigation bar of the site.

  16. Web Design Okotoks says:

    Dates are important and so is regular content. I write blogs everyday and make sure it shows the date on each.

  17. Rajesh Kumar says:

    Hi P.Chandra

    Thanks for this really nice tip and the code

    I’m looking for a plugin that can automatically insert contextual links in my blog post to the relevant posts on my other wordpress blogs, I’ve been tired of finding such a plugin, landed up here while searching some blah blah on Google,

    Please let me know if there is any such plugin/solution

    Thanks

  18. Wintch says:

    Thanks! That worked for my blog also :)

  19. mike says:

    just checking, Chandra. After i implemented it on my child theme, how do i know it is working for me? the Structural Tool will for the next few days, still show errors? i managed to resolve the authorship issue. now it is left with this.

    Please help :)

  20. Tom says:

    As long as you take the time read the blog post and have an opinion that you want to share, you just go for it. No special rules needed.

  21. Riya says:

    For sure I will do improvement the way I used to do commenting. Helped me lot to upgrade my knowledge.

  22. Yousuf says:

    Nice! Since search engines want us to be updating our content as much as possible then the date issue on posts really makes sense. I have surely liked your article.

  23. Itay says:

    It works!!
    For hebrew just replace the first updated with עודכן
    printf( ‘עודכן %3$s %5$s‘,
    esc_url( get_permalink() ),
    esc_attr( get_the_modified_date( ‘c’ ) ),
    esc_html( get_the_modified_date() ),
    esc_url( get_author_posts_url( get_the_author_meta( ‘ID’ ) ) ),
    get_the_author()

  24. Iggy Pritzker says:

    worked fine!

  25. Nico van Dijk says:

    Hi, this works great. However I would like the original date of publication to be visible for my readers as well. How can I combine it with your code?
    Nico

Leave a Reply

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




Next Article »
css.php