A fix for hentry error in WordPress

A fix for hentry error in WordPress

Google is getting stricter about how it rates your website. That much at least is clear.

I was recently looking at Google Webmaster tools regarding a WordPress website I look after. To my surprise it complained about a “hentry” error on 58 pages, or the total number of pages on the site.

This was a bit of a shock as the site has the Yoast plugin and I’ve gone to great lengths to optimise the pages as best I can.  Googling the hentry error didn’t initially help much either as the Theme I’m using didn’t appear to be similar in construction to any of the ones mentioned in the pages I found. Thus most of the fixes seemed irrelevant in my situation.

As far as I can tell the hentry tags are concerned with authorship of posts. Now this is fine when creating a blog however by default it seems at least some (the one I’m assuming at least) of the themes add this markup to “pages” as well. If you are creating pages on a theme that adds this to a page you will get an error since pages by default (as far as I know at least) do not apply authorship.

After a few attempts at searching for a fix I discovered two that work. The below one is the most elegant and you can find this at http://swampsidestudio.com/remove-wordpress-hentry-class/, or you can use the one below.

Now to remove the “hentry” markup from your “pages” add the below code to the top of the functions.php (directly under the <?php line) file in your theme directory (look in wp-content/themes… :

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

So this should in effect remove the “Hentry” tags from your pages and leave them in your blog posts.

Thanks goes to Swamp-Side Studio for this fix.

Leave a Reply