Remove WordPress hentry Class from Pages

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?

Force Browser to Use Latest WordPress CSS

Have you ever made changes to your WordPress theme’s CSS file, then asked your client to have a look only to have them say they don’t see the change? Often it’s because their browser has cached the old stylesheet. So you ask them to empty their browser cache, or press f5 or command+R, and you hear silence on the phone.

First, I found this post by Mark Jaquith: Force CSS changes to “go live” immediately. This worked great for a long time, but now wp_enqueue_style() is preferred, so that solution no longer worked.

Here’s what I do now to enqueue a style sheet with a timestamp:

function themeslug_enqueue_style(){
   wp_enqueue_style( 'style', get_stylesheet_directory_uri().'/style.css', array(), filemtime( get_stylesheet_directory().'/style.css' ) );
}
add_action('wp_enqueue_scripts','themeslug_enqueue_style');