How to fetch Gravatar avatar in PHP / WordPress Theme ?

Posted By: KP On February 12, 2011 Under Internet, Web Design Categories


Gravatar is globally recognized avatar, a free display picture service, by Automattic. As Gravatar is accepted everywhere on internet, it is recommended that one theme developer should use Gravatar in his theme.

For a new developer fetching Gravatar may seem a little difficult. I thought to provide complete code that you can use directly wherever you want.

Explanation:

Gravatar is based on user email ids. Each email is a different Gravatar. The fetching requires md5 hash of email id of a user. Please note that you need to change $email, in below code, for every user.

$default = “”; // link to your default avatar

[email protected]

$size = 32; // size in pixels squared
$grav_url = “http://www.gravatar.com/avatar.php?gravatar_id=
” . md5($email) . “&default=” . urlencode($default) . “&size=” . $size;
?>
<img src=”<?=$grav_url ?>” height=”<?=$size ?>” width=”<?=$size ?>” alt=”User Gravatar” />

$grav_url is image link.



Share with Friends ( Sharing is Caring! )


Subscribe For E-mail Notification Of Article Updates

Enter your email address:

NOTICE:
DO NOT FORGET TO CLICK ON THE VERIFICATION LINK AFTER SUBSCRIBING,THE VERIFICATION MAIL WILL BE SENT TO YOU FROM "FeedBurner Email Subscriptions".
( What is this? Why I need to do this?)

Related Posts

Post a Comment

OR