0Wordpress LogoRich Snippets code for Mystique 2.x

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 '

'.__('Homepage:','mystique').' <a href="'.$curauth->user_url.'">'.$curauth->user_url.'</a>

';
if($curauth->yim<>'') echo '

'.__('Yahoo Messenger:','mystique').' <a href="ymsgr:sendIM?'.$curauth->yim.'">'.$curauth->yim.'</a>

';
if($curauth->jabber<>'') echo '

'.__('Jabber/GTalk:','mystique').' <a href="gtalk:chat?jid='.$curauth->jabber.'">'.$curauth->jabber.'</a>

';
if($curauth->aim<>'') echo '

'.__('AIM:','mystique').' <a href="aim:goIM?screenname='.$curauth->aim.'">'.$curauth->aim.'</a>

';

add this extra line

if(($curauth->user_url<>'http://') && ($curauth->user_url<>'')) echo '

'.__('Homepage:','mystique').' <a href="'.$curauth->user_url.'">'.$curauth->user_url.'</a>

';
if($curauth->yim<>'') echo '

'.__('Yahoo Messenger:','mystique').' <a href="ymsgr:sendIM?'.$curauth->yim.'">'.$curauth->yim.'</a>

';
if($curauth->jabber<>'') echo '

'.__('Jabber/GTalk:','mystique').' <a href="gtalk:chat?jid='.$curauth->jabber.'">'.$curauth->jabber.'</a>

';
if($curauth->aim<>'') echo '

'.__('AIM:','mystique').' <a href="aim:goIM?screenname='.$curauth->aim.'">'.$curauth->aim.'</a>

';
if($curauth->google_profile<>'') echo '
<a href="' . $curauth->google_profile . '" rel="me">Google Profile</a>

';

Next, 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 title="'. sprintf(__(" href="'. get_author_posts_url(get_the_author_meta('ID')) .'" rel="author">'. get_the_author() .'</a>',
get_the_time(get_option('date_format')),get_the_time(get_option('time_format')), get_the_category_list(', '), '<a title="RSS 2.0" href="'.get_post_comments_feed_link($post->ID).'">RSS 2.0</a>');echo ' ';

Then, finally add the same rel=”author” to line 670 of core.php

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

</pre>
<h1 class="title"></h1>
<pre>

replace this with…

</pre>
<h1 class="title entry-title"></h1>
<h2 class="updated"></h2>
<h2 class="vcard"></h2>
<pre>

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

Got some thoughts of your own? Indulge yourself below by commenting! 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.

Leave a Reply