Google Search Console reported a bunch of structured data errors in a new WordPress blog I began recently. This was a surprise, because I didn't know I was offering structured data. The WordPress theme I've been using, Twenty Twelve, includes CSS styles in blog posts to support the hAtom microformat, which helps search engines recognize the components of a blog post such as the title, author and tags.
When Google crawled the blog, the Structured Data section of Search Console flagged 20 pages with the error "missing: updated," which indicated the data should have an element called
updated that isn't there.
I did some digging and found that WordPress bloggers are solving this problem in some complicated ways, like adding a plugin just to filter the structured data out. But I found an easier solution.
updated style indicates when a blog post was last updated. In every page that displays a blog entry,
updated should be in the HTML where the post time is displayed. Here's an example prior to the fix:
<time class="entry-date" datetime="2016-04-02T19:39:49+00:00">April 2, 2016</time></a>
Any blog post can include hAtom structured data by adding class names to the tags that surround an element. The
updated class should be added to the
time tag, turning the HTML into this:
<time class="entry-date updated" datetime="2016-04-02T19:39:49+00:00">April 2, 2016</time></a>
In the folder for my blog's theme, I found the file I needed to edit to add this fix:
functions.php. This file is a collection of PHP functions to enhance the theme and modify WordPress functionality.
In a function called
twentytwelve_entry_meta(), I found the line where the blog post's time is displayed. I edited the line to add the reference to
updated. Here's the line after the change:
$date = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date updated" datetime="%3$s">%4$s</time></a>', esc_url( get_permalink() ),
esc_attr( get_the_time() ),
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() )
I'm still learning about WordPress and not ready to make major changes to a theme's PHP code, but this fix is a minor adjustment to the HTML output, so I thought it would be safe to attempt. The fix was successful: When I test my blog's pages in Google's Structured Data Testing Tool they pass.
The fix I've described works in the Twenty Twelve theme -- and probably some of the other basic themes for WordPress. Because each theme has different HTML, you may find the code that displays the time someplace else.