Google’s Structured Data Testing Tool is strictly interpreting the use of the hentry class.

The hentry class is for date-stamped content intended to be syndicated, like blog posts. WordPress automatically adds the hentry class with the post_class function. Often post_class is used in templates like this:


<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

hentry Error in Google’s Structured Data Testing ToolMany WordPress themes, even WordPress default themes, use post_class on all content, including pages. WordPress pages, as opposed to posts, don’t usually include a date and author because pages are not date based. Google’s Structured Data Testing Tool sees the hentry class and expects to see date and author, so it lists errors. When Google lists errors, webmasters pay attention.

Remove WordPress hentry Class from Pages

To remove the hentry post class only from pages, this can be added to your theme’s functions.php:

function themeslug_remove_hentry( $classes ) {
	if ( is_page() ) {
		$classes = array_diff( $classes, array( 'hentry' ) );
	}
	return $classes;
}
add_filter( 'post_class','themeslug_remove_hentry' );

The screen grab below shows an example of how items with errors in the structured data report in Google Webmaster Tools drops to zero after removing the hentry post class.

hentry Structured Data Errors in Google Webmaster Tools

Should the WordPress core stop adding the hentry class to pages to satisfy Google’s strict interpretation of structured data?

26 thoughts on “Remove WordPress hentry Class from Pages

  1. I searched for 10 long, straight days for a solution to the rich snippets error messages on my website. I tried numerous solutions. None worked, that is, until I found yours. Finally, all of the error messages on all 20 pages of my website are gone. Thank you!

  2. Hi,
    I’m not a coder and have white paged my site several times now. On the code above, do I replace ‘themeslug’ with my theme name? Hueman or leave it. I’ve got over 600 errors on ‘tags’, so I’m trying to do what you said and remove the hentry. I put the code right after the header. Is that correct?

    Thanks so much!
    Nancie

      • Thank you. Now for my ‘idiot’ question. I have entered the code in several different places on my child theme page, but nothing changes. Where do I place it? Above Or below the footer? Or somewhere in content? (I downloaded a single.php file from the author that was supposed to fix it and it didn’t. So that’s what is in the child-theme function.php also.)

        These are the type pages that have errors:
        http://www.apertureofmysoul.com/tag/tourist/

        Sorry for all the questions! I’m losing my mind trying to fix this!

        • Nancie,

          The code snippet only goes in your theme’s functions.php file.

          My example code is intended to remove the hentry class only from pages. Your tag archives are not pages, so my code snippet will have no effect.

          The hentry class is for date-stamped content like blog posts, so having the hentry class in your tag archive should be fine as long as it contains a date and author.

          • Thank you Mike! I was hoping it was my fix. I only had 49 errors before I changed themes to what I thought was a better theme. Now with 660 errors in my webmaster files and no answer to fix them, I’m discouraged.

            I appreciate your time immensely!

            Have an awesome week!

    • Google wants high-quality web pages in their search results. Major HTML errors that would cause a web page to not render properly in a browser could have a negative influence on search result position.

      This article is about a minor HTML error that should not affect a search result position. This article is more about the last sentence, “Should the WordPress core stop adding the hentry class to pages to satisfy Google’s strict interpretation of structured data?”. WordPress is introducing this error, and I think it should be fixed.

      Here’s an answer straight from Google:

      http://youtu.be/2XlKn6I9rSc

  3. Hi, i am using word press meso column theme, the code you provide above doesn’t present in my functions.php file. Is there any another file where i can found this code??

  4. Sir I have placed the following code :

    function Twenty_Fourteen_remove_hentry( $classes ) {
    if ( is_page() ) {
    $classes = array_diff( $classes, array( ‘hentry’ ) );
    }
    return $classes;
    }
    add_filter( ‘post_class’,’Twenty_Fourteen_remove_hentry’ );

    1. Is it Ok

    2. Like i have just added the code , Will it take some time that google search console / webmaster tool to take shown me no ERROR

    • “themeslug” can be replaced with anything. In your case you could use “flatsome”. You could open your theme’s functions.php file and see what function prefix they are using. The idea is to create a function with a unique name to reduce the possibility of conflicts.

  5. Great article and very helpful knowing these errors on Google are only considered minor HTML issues and not going to hurt search placement.

    Just clarifying the naming part –

    my theme is u-design and I’m using a child theme called u-design-child

    in this function, do I change “themeslug” to “u-design” or “u-design-child” ?

    Thanks

  6. Hello,

    I have “updated” and “author” errors which have affected rich snippet images for my recipes showing up in my google search results. If i remove hentry class will this help rich snippet images to appear in google again?

    I entered the code in functions.php but when I updated it came up with an error like my site had crashed. I quickly went back and took it out. I’m wondering where in the functions.php file do you paste it?

    This is the last code in my functions.php file:
    //
    (function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,’script’,’//www.google-analytics.com/analytics.js’,’ga’);

    ga(‘create’, ‘UA-65374635-1’, ‘auto’);
    ga(‘send’, ‘pageview’);

    Do I put the code before I put it after when it came up with an error.

    I use simplecatch theme so the code I was pasting was:

    function simplecatch_remove_hentry( $classes ) {
    if ( is_page() ) {
    $classes = array_diff( $classes, array( ‘hentry’ ) );
    }
    return $classes;
    }
    add_filter( ‘post_class’,’simplecatch_remove_hentry’ );

    • This article is intended to help remove errors in the structured data report in Google Webmaster Tools. I’m not sure how removing the hentry class will affect the appearance of search results.

      The code you are pasting into your functions.php file looks okay. I’m not sure why the Google Analytics code is in your functions.php file like that. You might want to get an expert to look at it for you.

  7. Everybody… There is a difference between fixing these errors and removing these errors. Microformat functionality should NOT be removed (which is what all of you are doing) – it should be fixed. All of the above is bad advice. The errors have nothing to do with WordPress core and everything to do with sloppy and outdated theme development. Microformat data was introduced in 2005… that was 11 years ago. Also in May of 2009 Google announced that they would start parsing the hCard, hReview and hProduct Microformat to populate search result pages. So NOT having this data limits your website’s accessibility and most certainly limits the data that can be easily extracted from your posts when shared. Do you really believe that Google would be showing Microformat errors in Search Console or even giving us testing tools to fix these errors if they didn’t care about them?

    If you are getting these errors in search console, simply make sure your theme files are including the correct tags/classes within your post’s html. WordPress did not introduce this error… sloppy theme authors did when they failed to include correct markup within their templates and files.

    • Tad, please help us understand your position. When Google sees the hentry class it expects to also see a date and author, but WordPress pages (not posts, but post_type ‘page’) do not reveal the date and author. That is the issue.

      It appears that WordPress — not the theme — is adding the hentry class with the post_class function. With a clean WordPress install, with no plugins and the latest Twenty Sixteen theme, a page will include the hentry class, but no date and author.

      With this blog post I am questioning whether WordPress core should include the hentry class on pages.

  8. I see your point Mike. My view is that the more Google (or web crawlers in general) know about a page or post – the better. As an example – think about hentry support for modified times on page content. By making sure your page timestamps are correct, you can be sure to tell web crawlers that your content is being updated and is relevant in 2016 (even if it was originally published in 2008). I hope that clarifies my viewpoint on why this type of data is/can be beneficial.

    If anyone here is unsure what markup their theme is outputting on their pages and posts, use Google’s tool for testing. https://search.google.com/structured-data/testing-tool

  9. Awesome!I went from 20,000 structured data hentry errors to 1,800 in 5 minutes. How would I get rid of the remaining 1,800 or would I just wait for Google to re-index my site? Thanks…

Leave a Reply

Your email address will not be published. Required fields are marked *