18Wordpress LogoResolving problems with Google’s Rich Snippets Testing Tool

Published on by in Web Technologies. Updated 1st October 2011.

In addition to this site I have a personal blog where, amongst other things, I post recipes.  I’ve recently discovered google’s new recipe search, and have been looking to implement support for microformats / microdata.  Google provide a tool for checking your markup, called the “rich snippets testing tool“.  When I tried validating one of my recipes, I encountered various errors, which have taken me a while to track down and resolve. 

Each one is independent, but related, and in all cases the number of errors you are likely to encounter depends largely on the theme you use with your blog.  In my case, using the mystique theme, I encountered a substantial number of errors.

1. The first problem was with the author information / hrecipe section

The solution:

You need a google profile.  Your google profile must be linked from somewhere on the page, with rel=”me”, AND the main domain of your website must be listed on your google profile links.

I achieved this with the Mystique theme with a series of modifications.

Firstly, I added the code from yoast (as shown below) to functions.php

function yoast_add_google_profile( $contactmethods ) {
// Add Google Profiles
$contactmethods['google_profile'] = 'Google Profile URL';
return $contactmethods;
}
add_filter( 'user_contactmethods', 'yoast_add_google_profile', 10, 1);

Second, I went to my wordpress profile page and filled in the google profile field with a link to my google profile

Third, I edited a line to author.php, again, based on information from yoast, but changed for the Mystique theme

in this section

if(($curauth->user_url<>'http://') && ($curauth->user_url<>'')) echo '<p class="im www">'.__('Homepage:','mystique').' <a href="'.$curauth->user_url.'">'.$curauth->user_url.'</a></p>';
if($curauth->yim<>'') echo '<p class="im yahoo">'.__('Yahoo Messenger:','mystique').' <a href="ymsgr:sendIM?'.$curauth->yim.'">'.$curauth->yim.'</a></p>';
if($curauth->jabber<>'') echo '<p class="im gtalk">'.__('Jabber/GTalk:','mystique').' <a href="gtalk:chat?jid='.$curauth->jabber.'">'.$curauth->jabber.'</a></p>';
if($curauth->aim<>'') echo '<p class="im aim">'.__('AIM:','mystique').' <a href="aim:goIM?screenname='.$curauth->aim.'">'.$curauth->aim.'</a></p>';

add this extra line

if(($curauth->user_url<>'http://') && ($curauth->user_url<>'')) echo '<p class="im www">'.__('Homepage:','mystique').' <a href="'.$curauth->user_url.'">'.$curauth->user_url.'</a></p>';
if($curauth->yim<>'') echo '<p class="im yahoo">'.__('Yahoo Messenger:','mystique').' <a href="ymsgr:sendIM?'.$curauth->yim.'">'.$curauth->yim.'</a></p>';
if($curauth->jabber<>'') echo '<p class="im gtalk">'.__('Jabber/GTalk:','mystique').' <a href="gtalk:chat?jid='.$curauth->jabber.'">'.$curauth->jabber.'</a></p>';
if($curauth->aim<>'') echo '<p class="im aim">'.__('AIM:','mystique').' <a href="aim:goIM?screenname='.$curauth->aim.'">'.$curauth->aim.'</a></p>';
if($curauth->google_profile<>'') echo '<p><a href="' . $curauth->google_profile . '" rel="me">Google Profile</a></p>';

Finally, I edited single.php to add rel=”author” to the link to my author page.  In the Mystique theme this is found towards the bottom of the file, within the (long) line(s) as shown below. I have added the rel=”author” at the end of the first line before the href=” part

printf(__('This entry was posted by %1$s on %2$s at %3$s, and is filed under %4$s. Follow any responses to this post through %5$s.', 'mystique'), '<a rel="author" href="'.
get_author_posts_url(get_the_author_meta('ID')) .'" title="'. sprintf(__("Posts by %s","mystique"), attribute_escape(get_the_author())).' ">'. get_the_author() .'</a>',
get_the_time(get_option('date_format')),get_the_time(get_option('time_format')), get_the_category_list(', '), '<a href="'.get_post_comments_feed_link($post->ID).'" title="RSS 2.0">RSS 2.0</a>');echo ' ';

When this is correctly implemented you should get a success message in the snippets testing tool which reads Verified: Authorship markup is correct for this page

2. The second problem(s) were with the hfeed / hentry section and included the following:

Missing required hCard “author”.
Warning: At least one field must be set for Hcard.
Warning: At least one field must be set for HatomEntry.
Warning: Missing required field “entry-title”.
Warning: Missing required field “updated”.
Warning: Missing required hCard “author”.

The solution(s):

Use the wordpress editor to edit single.php

Find the code

<h1 class="title"><?php the_title(); ?></h1>

replace this with…

<h1 class="title entry-title"><?php the_title(); ?></h1>
<h2 class="updated"><span class="value-title" title="<?php the_date(); ?>"></span></h2>
<h2 class="vcard"><span class="fn"><span class="value-title" title="<?php the_author(); ?>"></span></span></h2>

A final note – Don’t just copy and paste the code from this page, as for some reason (I’m guessing character encoding) it wont work.  Copy it from here and paste into windows notepad.  Then re-copy it from windows notepad (or any other basic plain-text-only editor) and paste into the wordpress editor.  Going via notepad loses any hidden encoding or other data which causes a problem so the code is treated as the plain-text it is supposed to be!

Update…

The new version of the mystique theme (v3) requires slightly different changes for part 1. There are 2 differences…

1. Instead of the 3rd edit find this

<?php if(($app->author->get('user_url')) && ($app->author->get('user_url')!== 'http://')): ?>
<p class="im www">
  <?php _ae('Home page:'); ?> <a href="<?php echo $app->author->get('user_url'); ?>"><?php echo $app->author->get('user_url'); ?></a>
</p>
<?php endif; ?>

And add the following

<?php if(($app->author->get('google_profile')) && ($app->author->get('google_profile')!== 'http://')): ?>
<p class="im www">
  <?php _ae('Google Profile:'); ?> <a rel="me" href="<?php echo $app->author->get('google_profile'); ?>"><?php echo $app->author->get('google_profile'); ?></a>
</p>
<?php endif; ?>

2. Instead of the final step (editing single.php) I instead edited AtomObjectAuthor.php and changed line 213 by adding rel=”author” so it reads as follows

return '<a rel="author" href="'.$this->getPostsURL().'" title="'.$title.' ">'.$this->getName().'</a>';

Think we’ve missed something? Let us know by commenting below. If you would like to subscribe please use the subscribe link on the menu at the top right. You can also share this with your friends by using the social links below. Cheers.

18 Responses to “Resolving problems with Google’s Rich Snippets Testing Tool”

  1. Harald

    Thanks very much for this article.

    I used this, even I have the zBench theme:

    <span class="value-title" title="”>
    <span class="value-title" title="”>

    in order to solve these problems:

    Warning: Missing required field “entry-title”.
    Warning: Missing required field “updated”.
    Warning: Missing required hCard “author”.

    Now, when checking with the
    Rich Snippets Testing Tool
    http://www.google.com/webmasters/tools/richsnippets
    all is fine AS LONG AS I check on single post level, e.g.
    http://www.mediawireless.eu/2012/seo-pr-suchmaschinenoptimierung-public-relations/
    but it is still not ok, when checking the domain only
    http://www.mediawireless.eu/

    Any idea, help or suggestion?

    Best, Harald

    Reply
    • Jon Scaife

      What file(s) did you edit? The index page (and archive pages) are often generated using a different PHP file. If you edited single.php you might also need to edit index.php or archive.php. If that IS the case you may also need to edit page.php search.php and author.php if they exist. Different themes do it different ways

      On the plus side, if you’ve got it working on single posts your 95% of the way there :)

      Reply
  2. Rob Cairns

    On one site I am working on running Genesis with no child theme, I am still having an error. can you make a suggestion Jon? The error is : Warning: Missing required field “updated”. with the full txt below.

    Thanks

    Rob

    hfeed
    hentry
    entry-title = Win a Copy of Picture Collage Maker Pro for Windows
    entry-content = Nothing delights me more than discovering affordable, easy to use software that will allow me to have fun creating unique, lasting memories with pictures. My good friend Shannon over at Coupon…
    published = 03/26/2012
    hcard
    fn = Jean Parks
    Rel
    name = Win a Copy of Picture Collage Maker Pro for Windows
    rel = bookmark
    url = http://www.theshoppinqueen.com/win-copy-picture-collage-maker-pro-windows
    Rel
    name = View all posts in Giveaways
    rel = tag
    url = http://www.theshoppinqueen.com/giveaways
    Warning: Missing required field “updated”.

    Reply
    • Jon Scaife

      Yep. You have a “published” field, but not an “updated” field. If you want to do a “quick fix” you can just add class “updated” to the same class as “published” (e.g. so span class=”published” becomes span class=”published updated”. Strictly tho, if you update a post you’ll be supplying incorrect data, so when I’ve done edits I’ve edited the PHP to check if the post has been updated. If it hasn’t then the output is exactly as above, but if the post has been updated then I output 2 spans, one with the published date and one with the updated date and apply an appropriate span to both.
      Hopefully the above makes sense and you can sort it, but if it doesn’t then gimme another shout. You can always use the form on the about page to send me e-mail and then maybe send me the file in question for me to have a look at.

      Reply
  3. noskill1343

    Warning: At least one field must be set for Hcard.
    Warning: Missing required field “updated”.

    I have same problem, but in blogspot, any suggestion?
    I try to remove hfeed and hentry, but rich snippet still not works

    Reply
    • Jon Scaife

      You can’t remove hfeed and hentry and expect rich snippets to work
      You need to add some tags. Lets assume the the “hfeed” and “hentry” are classes applied to 2 nested divs. Inside the inner div (with class “hentry”) you need another tag (probably a div, span or p) with the hcard stuff (via classes). You also need another tag with class=”updated” and inside that tag you need the updated date for the post. The easiest way to do this is to just add class=”updated” to the existing container for the updated date information. I don’t use blogger so I can’t tell you exactly how off the top of my head, but if you can’t figure it out drop me another shout and I’ll sign back up for blogger and sort some code for you. If you do manage to fix it, it would be great if you could post below (or e-mail me) to let us know how you fixed it. Sorry for the delay replying, it’s been a very busy couple of weeks. Cheers :)

      Reply
  4. darko kovancives

    hi, once again many thanks. I’ll write an article about you, you are king when it comes to seo.

    Reply
  5. darko kovancives

    how i add this codes in thesis theme ? single.php not exist in thesis folders.

    Reply
    • Jon Scaife

      Without knowing what files you do have I can’t say. Unless I’m mistaken Thesis isn’t a free theme so I can’t have a look at it. Assuming it uses the standard Template Hierarchy I’d guess that the code would be somewhere in index.php. In my experience though it is more likely that index.php will be quite short and probably pulls in other files. Start by looking in index.php and if you get no luck zip a copy of index.php up, stick it up somewhere and send me the url and I’ll have a look.

      Reply
  6. m33r4

    Hi there. I have created my recipe snippet but getting the following error code and I truly don’t know how to rectify that:

    Extracted rich snippet data from the page
    hrecipe
    Warning: At least one field must be set for Hrecipe.
    hrecipe
    Warning: At least one field must be set for Hrecipe.

    Help please?

    Many thanks.

    Reply
  7. Gaurav Ekka

    finally corrected the

    Warning: At least one field must be set for Hcard.
    Warning: At least one field must be set for HatomEntry.
    Warning: Missing required field “entry-title”.
    Warning: Missing required field “updated”.
    Warning: Missing required hCard “author”.

    Thank you Jon

    Reply

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>