WordPress and Google Search Console Structured Data Error for hentry

structured-data-errorsIf you are using Google Search Console and you see your WordPress website has several errors in the “Search Appearance” -> “Structured Data” section, this tutorial may help you fix your problem.  All of my errors were in “Structured Data > hentry (markup: microformats.org)”.  If you are not familiar with hentry, it is a rich snippet that allows Google and other search engines more easily read data on your website.  In WordPress hentry is simply a CSS class declared on the parent element of your article.  The hentry contains: entry-title, updated, published, author, bookmark, url, tags, etc.

Nuclear option: remove all “hentry” references

No hentry CSS class means no hentry errors in the Search Console. You may not want to mess with fixing it the good way keeping it’s value.  You just want to get rid of the errors. The solution is to add this function to your theme’s functions.php file:

 //Remove the Hentry Class Every
function remove_hentry( $classes ) {
 $classes = array_diff( $classes, array( 'hentry' ) );
 return $classes;
}
add_filter( 'post_class','remove_hentry' );

To test if the function worked, go to a page with the error, view the source code and search for “hentry”, if it is not there, problem solved.

The best way to fixing the hentry Google Search Console errors

Fixing the errors requires knowledge of HTML, PHP, and the WordPress structure.  You must know where the error is occurring; on what page(s).  Sadly all themes structures are different.  The file to fix these problems could be called: “functions.php”, “archive.php”, “index.php”, or many other combinations of files. For me the error was on the blog, archives, and category pages, but not on the single post pages. The source of my error was in 3 different files all related to the post loop usually found in the files mentioned above.  I have simplified my code to show you an example of how i fixed the “Structured Data > hentry (markup: microformats.org)” errors:

Inside of the loop the looks like this:

if ( have_posts() ) : while ( have_posts() ) : the_post();

You will find something like this (example of what might be in your theme file):

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php the_title('<h2 class="post-title"><a href="'. get_permalink() .'">', '</a></h2>'); ?>
<div class="meta">
 <span class="date"><?php the_time( get_option('date_format') ); ?></span>
 <span><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"><?php the_author(); ?></a></span>
 <?php if( has_category() ) : ?>
 <span class="categories"><?php the_category(', '); ?></span>
 <?php endif; ?>
</div>
<?php the_excerpt(); ?>
</div>

hentry-missing-errorsAll of the data is already there, we just need to use the correct CSS class names to fix the rich snippets errors.  My errors were: Missing: author, Missing: entry-title, and Missing: updated.  As you can see above the CSS classes “author”, “entry-title”, and “updated” are not listed.  So we need to add the classes.  Note: the “author” class needs to have some other elements / CSS classes associated with it “vcard” and the child element actually containing the name “fn”.

Here is the fixed and final version:

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php the_title('<h2 class="post-title"><a class="entry-title" href="'. get_permalink() .'" rel="bookmark">', '</a></h2>'); ?>
<div class="meta">
 <span class="date updated published"><?php the_time( get_option('date_format') ); ?></span>
 <span class="vcard author"><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>" class="fn"><?php the_author(); ?></a></span>
 <?php if( has_category() ) : ?>
 <span class="categories">
 <?php the_category(', '); ?>
 </span>
 <?php endif; ?>
</div>
<?php the_excerpt(); ?>
</div>

What was done:

  • For the Title: I added the class “entry-title” and rel=”bookmark” to the <a tag.
  • For the Date: I added the classes “updated” and “published” to the parent element.
  • For the Author: added to a parent element the classes “vcard” and “author”.  To the child element containing the text I added the class “fn”.

Testing the changes made:

After that I tested my rich snippet changes with Google Webmaster’s Structured Data Testing Tool.

I made any adjustments of typos, etc and after that the errors went away.  I hope this will help you troubleshoot your “Structured Data > hentry (markup: microformats.org)” WordPress errors.

More resources:

  • Lorelle on WordPress – I went this blog it is highlighted some examples of using micro-formats in WordPress, however the instructions are a bit dated.  This article however sent me down the path to the solution.
  • Accelerator Marketing – How to Fix Structured Data Errors Showing in Google Webmaster Tools. Of course I found this link after I fixed my own website.
  • Many blogs online tell you to just disable the hentry data by removing the class from WordPress (ex. Swamp-Side Studio’s article Remove WordPress hentry Class from Pages).  Remove the class will solve the problem, but a better solution is keeping the hentry class and fixing the errors.