How to Add Updated Date to WordPress Articles

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.

Share with friends

29
Leave a Reply

avatar
25 Comment threads
4 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
26 Comment authors
Nico van DijkIggy PritzkerItayYousufRiya Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Madhav Tripathi
Madhav Tripathi

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

Per Soderlind
Per Soderlind

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() )… Read more »

Darrel
Darrel

I have hardly any idea of how to do this. I’m using thesis theme, so if I copy/past this code into the functions.php it will work?

Clay Morisson
Clay Morisson

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

fenny
fenny

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

Web Consultant
Web Consultant

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

Nancy Badillo
Nancy Badillo

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.

Souri
Souri

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 …

Shital Bhalani
Shital Bhalani

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

Priyanka Jain
Priyanka Jain

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.

BestofBacklinks
BestofBacklinks

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.

Deep
Deep

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

Technology Blog and Tutorial
Technology Blog and Tutorial

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

PR Agency San Francisco
PR Agency San Francisco

Hi,

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

sharma
sharma

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.

Pradeepkumar V D
Pradeepkumar V D

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

Web Design Okotoks
Web Design Okotoks

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

Rajesh Kumar
Rajesh Kumar

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

Wintch
Wintch

Thanks! That worked for my blog also :)

mike
mike

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 :)

Tom
Tom

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.

Riya
Riya

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

Yousuf
Yousuf

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.

Itay
Itay

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()

Iggy Pritzker
Iggy Pritzker

worked fine!

Nico van Dijk
Nico van Dijk

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