Posted by December 24, 2011on
Several days ago I checked what Google’s Rich Snippets Testing Tool thinks about this WordPress-based blog. The results were not bad in general, but also not good enough for my understanding. While Google was able to detect that I am the owner of the blog and presented a link to my Google+ Profile, and the main page of the blog was correctly detected as a list of blog entries, each one with the permalink, a list of tags and a list of categories – the most important things were missing: the title, the date and the author of the post. The following errors were displayed for each blog entry:
Warning: Missing required field “entry-title”.
Warning: Missing required field “updated”.
Warning: Missing required hCard “author”.
Obviously, I started to check what can be done about that. This research lead me to the long list of articles about microformats, how they are used in Google’s Rich Snippets and how they are handled by WordPress.
To summarize what should be done:
In order for Google to properly detect the “missing” information (which actually appears on the page), it should be properly marked with meta-information elements (in this case – hAtom microformat). This is accomplished by adding special class to the HTML elements containing the relevant text. Sometimes the nearest surrounding element contains much more text than needed; in this case you can enclose the relevant part of the text in the dedicated “span” element – in this way you do not break existing formatting.
For the blog post, the title of the post should be marked with class “entry-title“, the posting date should be marked with class “updated” and the full name of the post author should be marked with class “author” accomplished by elements from hCard microformat – “vcard” and “fn“. The sample for this post will be:
<span class=”entry-title”>How to fix “missing required fields” warnings in Rich Snippets Testing Tool</span>
<span class=”updated”>December 24, 2011</span>
<span class=”vcard author”><span class=”fn”>Anton Khitrenovich</span></span>
Now, let’s take a look on how to do this in WordPress:
As you can see, the information we need already appears on the page, so it should be pretty simple to mark it with relevant microformat. The simplest way that I found to implement the changes was to modify some theme files directly*, via Theme Editor (you can find it under “Appearance” => “Editor” in the Admin Interface of your blog). Here is an example of such modification for the main blog page (“index.php” template) of Andreas09 theme; note that “class” attributes besides the “date” are new. (The whole snippet is indented for easier reading.)
There are two additional templates you will probably want to modify – “single.php” is the template of the single post and “archive.php” is the template for various post listings, such as posts by date, by tag and by category. You may also want to modify “search.php” (the template that displays search results), but I’m not sure about the actual effect of this modification.
Disclaimer: Implementation of the changes I suggested in your blog is at your own risk!
* Notes about direct theme modification:
- No, I did not find any WordPress plugin that can insert the required markup for you. It does not mean that such one does not exist at the moment of reading, especially if you read this page much later than the moment of writing.
- Yes, I know that touching the theme files directly is not recommended. In case the theme you are using for your WordPress blog is updated frequently (or at least maintained), it may make sense to wait for the theme update or just ask the author to add the microformats support. This is not the case for Andreas09 (used in this blog), which was last updated more than 5 years ago…