WordPress comment gravatars
Now that gravatar are part of the Automattic family… WordPress 2.5 has the get_avatar() function
echo get_avatar( $email); //sends an md5 hash of the email, returns the user avatar or if nothing found returns the gravatar.com default image
$default =”http://mysite.com/images/no_gravatar.jpg”
$size = ‘80′ //px square image
$email = $comment->comment_author_email //if we’re looping though comments…
But, for the theme designer, not all WordPress installs will be running 2.5 (possibly because as of today it doesn’t work 100%) - so test for the function first and supply an alternative.
if (function_exists(’get_avatar’)) {
echo get_avatar( $email, $size, urlencode($default));
} else {
//for WP < 2.5
$gravatarBase = “http://www.gravatar.com/avatar.php?gravatar_id=”
$gravatarUrl = sprintf(’%s&default=%s&size=%s’, md5($email), urlencode($default), $size);
echo “<img src=’$gravatarUrl’ />”;
}
Other avatars are available…









