Freshy 2 & Gravatar Bugfix
June 16, 2008 | 10:52 amPlease Note: [update 2008-08-20]: This has now been fixed as of Freshy 2.0.8, so you shouldn’t need to make any changes other than updating to the latest version. I am leaving this post for the sake of archive.
Any regular readers (although I don’t think I actually have any!) of this blog will notice I recently changed the theme to the fantastic Freshy 2 theme from Jide.fr. Together with the customise plugin it’s a great theme with many great features, including support for the Gravatar plugin.
Unfortunately as of version 2.0.6 there’s a very small error in the way the Gravatar function is implemented, which means the Gravatars aren’t displayed properly (and in fact it means commenter’s email addresses are displayed in the source).
Luckily the fix is very simple. You need to edit the file comments.php (using the theme editor or your favourite method), and find the following section (around line 37)(sorry about the indentation – WordPress insists on removing it!):
<?php // gravatars
if (function_exists('gravatar')) {
if ('' == $comment->comment_type) {
echo '<img class="avatar" src="';
gravatar($comment->comment_author_email);
echo '" alt="'.$comment->comment_author.'" width="40" height="40" />';
} elseif ( ('trackback' == $comment->comment_type) || ('pingback' == $comment->comment_type) ) {
echo '<img class="avatar" src="';
gravatar($comment->comment_author_url);
echo '" alt="'.$comment->comment_author.'" width="40" height="40" />';
}
} else {
//echo '<img class="avatar" src="'.get_bloginfo('stylesheet_directory').'/images/default_avatar.png" alt="'.$comment->comment_author.'" width="40" height="40" />';
}
?>
And you need to change the two gravatar() function calls to look like this (remove the paramters):
gravatar();
If you prefer you can download a fixed comments.php to replace you existing one here:
These changes actually make a lot of the code redundant, as it’s not possible to display a Gravatar for a trackback (there is no email address)
Make the above changes and you should be able to see Gravatars for all your visitors!
I also note, it looks that as of WordPress v2.5, that gravatar support is built in. Note, if you use this the get_avatar() function does require the email address of the user as a parameter!
Update: Please note, the above download is for the old Frshy 2.06. Freshy 2.07 may have a different comments.php file, although it still has the bug so you will need to make the repair manually (let me know if you have any questions)!
Update 2: The bug is now fixed as of version 2.0.8