SEO tip: Fix hentry errors in Google Webmaster Tools

If you are using WordPress, you could be hindering your SEO with invalid structured data.

To quickly find out if you are getting hentry errors, log into Google Webmaster Tools and look at “Search Appearance” > “Structured Data”.

Structured Data tool in Google Webmaster Tools

hentry errors in Google Webmaster ToolsLook at the data type ‘hentry’. Are you getting errors? Then read on for the fix!

(NB: in the Google Structured Data Testing Tool this does not show up as an error!)

About hentry: here be content

“hentry” is a class that is added automatically by WordPress to the block on your page that contains the post. It is part of the hAtom specification, and indicates to search engines that there is content that can be syndicated. In other words: ‘this block contains an article that can be displayed in feeds‘.

In order for search engines and other bots to extract the article, they need to find at least the title, content, author and publishing date. These are indicated by their own classes ( entry-title, entry-content, author, and published respectively).

Most themes will use the classes above to indicate to bots what piece of content is what exactly, so they can read the page more easily.

The problem

The fields listed above are required for a hentry to be parsed. But Pages generally don’t display the author and published date!

WordPress adds the hentry class automatically when the theme uses post_class(), regardless of post type. Some theme authors refrain from using post_class() for post types that are not blog posts, others use the trick below to prevent hentry to be added to Pages.

If you are getting the error, your theme probably does no such thing!

The solution

The solution is to disable hentry altogether for post types that do no sport an author or date.

Add the following snippet to your child theme functions.php or your functions plugin:

/**
 * Only use 'hentry' for post types with author and published date
 */
function remaintenance_remove_hentry( $classes, $class, $post_id ) {
    $hentry_post_types = array(
        "post"
    );

    $post_type = get_post_type( $post_id );

    if ( !in_array( $post_type, $hentry_post_types ) ) {
        $classes = array_diff( $classes, array( 'hentry' ) );
    }

    return $classes;
}
add_filter( 'post_class', 'remaintenance_remove_hentry', 10, 3 );

You can add extra post types to $hentry_post_types to add hentry to other post types too.

Getting errors for blogs too?

If you are getting the error for blogs too, that means that the author and published classes are not added to posts! To fix this, you can disable hentry for posts as well, by remove post from $hentry_post_types in the above snippet.

Alternatively, you can fix your (child)theme by adding the author and published classes to your single.php.

Don’t want to worry about how WordPress internals hinder your SEO performance? Then have a look at Remaintenance! We will pro-actively monitor your website for any performance and SEO issues, and solve things as they come up, so you can focus on your content.

7 Comments
  • Dovid de Bresser
    Posted at 05:56h, 28 August Reply

    How to add author etc. to pages in the Twenty Fourteen theme?

  • cara
    Posted at 15:41h, 25 October Reply

    done with folow this article… thanks…

  • brihaspathi
    Posted at 01:09h, 20 November Reply

    you are saying solution is for wordpress i want to know about blogger please give solution for solving structured data errors in blogger.

  • lenovo service
    Posted at 23:53h, 03 February Reply

    Hi friend, Im also getting this error, I tried but i couldn’t solve. Can you tell the solution for me.

    Structured Data
    Status: 1/28/17
    31 Items with Errors
    on 17 pages

    Data Type Source Pages Items Items with Errors
    hentry Markup: microformats.org 17 31 31
    LaptopStore Markup: schema.org 67 67 –
    LaptopShop Markup: schema.org 11 11 –
    WebSite Markup: schema.org 1 11 –
    hcard Markup: microformats.org 1 11 –

    Thanks
    Lenovo Service

  • Aditi Aggarwal
    Posted at 00:29h, 06 June Reply

    thanks for sharing great article with us. it is very help ful for me.

  • Praveen
    Posted at 15:35h, 27 July Reply

    Very nice article, helped me a lot, thanks for sharing,what about my website: businessandlifeonline.com , will try its best to bring high quality blogs which can help working employees like you to start your online business initially with out quitting your job and then be your own boss as your business grows.

  • Harsh Mishra
    Posted at 05:10h, 02 August Reply

    Can you tell me how to do it in blogger blogs?

Post A Comment