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.
The errors were caused by missing updated class in the hatom microdata.
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 in Twenty Fourteen Theme
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.
- 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.
- Updated Class – Add the updated class to the date so that the hentry microdata becomes valid and the structured data errors are gone.
- 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.