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…

Bookmark: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google
  • SphereIt
  • StumbleUpon
  • Technorati
  • YahooMyWeb

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment