Display a User Gravatar from an Email Address

  $gravatar_link = 'http://www.gravatar.com/avatar/' . md5($comment_author_email) . '?s=32';
   echo '<img src="' . $gravatar_link . '" />';

The variable "$comment_author_email" would be a string of a valid email address. If the email isn't in the Gravatar database, it will return a default graphic. "$comment_author_email" is the default WordPress variable that populates from a cookie for people who have previously commented (if the theme supports it).


  1. User Avatar
    Tymon Sturgeon

    Thanks! This is exactly what I was looking for!

    • User Avatar
      Kishan Sharma
      Permalink to comment#

      Really cool tip Sir i was searching same from centuries. Thanks a lot

  2. User Avatar
    Christopher Geary

    Thanks a million, I noticed that WordPress had the ability to show Avatars, But i couldn’t for the life of me work out how to add them. Saw this post, and thought I would give it a go. :)

    Also, this should post my gravatar i presume?

  3. User Avatar
    Permalink to comment#

    Cool :D One module goes trash bin :)


  4. User Avatar
    Permalink to comment#

    Great !!!

  5. User Avatar
    Permalink to comment#

    its great

  6. User Avatar

    this is cool, how would someone do a check that gravatar is reachable or is online and provide a fallback if gravatar isn’t reachable or user is offline?

Leave a Comment

Posting Code!

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.