Every month around the 15th and 30th, I check Google Webmaster to see if there are any 'errors' I need to address. Most of the time this is 404s on pages that were wrong for 30 minutes, and Google decided to crawl me right then. In January, I got a bunch of new alerts about 'structured data.'

What is it?

Google uses structured data that it finds on the web to understand the content of the page, as well as to gather information about the web and the world in general. Which is a fancy way of saying Google looks for specific classes and attributes in your page to determine what's what. 

Most of the time, your theme handles this for you. It's why you see hentry and authorcard in your page source. This is part of telling Google what the content is, contextually.

Bad Errors

Sadly, Google's report just said I had "missing fn" errors and gave me this:

itemtype: http://microformats.org/profile/hcard
photo: https://secure.gravatar.com/avatar/CODE?s=118&d=retro&r=g

That's not very helpful unless you already know what you're looking for. And even then… There was a link to test live data and I clicked on it, only to get a report back that I had no errors. Frustrating, right?

Then I checked a different error:

Missing: author
Missing: entry-title
Missing: updated

That was a little better, I thought, and I found out that since we'd removed author and updated from those posts, for a valid reason mind you, that was showing an error. The 'easy' fix was to make this function:

function microformats_fix( $post_id ) {
	$valid_types = array( 'post_type_authors', 'post_type_characters', 'post_type_shows' );
	if ( in_array( get_post_type( $post_id ), $valid_types ) ) {
		echo '<div class="hatom-extra" style="display:none;visibility:hidden;">
			<span class="entry-title">' . get_the_title( $post_id ) . '</span>
			<span class="updated">' . get_the_modified_time( 'F jS, Y', $post_id ) . '</span>
			<span class="author vcard"><span class="fn">' . get_option( 'blogname' ) . '</span></span>
		</div>';
	}
}

And then I just tossed it into my post content.

Does This Matter?

Kind of. It doesn't appear to actively hurt your SEO but it can help a little. In my case, I'm not actually using 'Author' so it's an inconvenience. And I don't want to make public when a page was last updated, since it's meant to be static content, but also it gets 'saved' a lot more than it gets updated, due to how I process some data. Basically it would lie to users.

But. Apparently I get to lie to Google.

Yaaay.

Reader Interactions

Comments

  1. Would this function work if added to the theme’s functions.php?

Leave a Reply

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

%d bloggers like this: