Treehouse: Grow your CSS skills. Land your dream job.

Last updated on:

Display a User Gravatar from an Email Address

<?php
  $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).

Comments

  1. Tymon Sturgeon

    Thanks! This is exactly what I was looking for!

    • Kishan Sharma
      Permalink to comment#

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

  2. 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. Zen
    Permalink to comment#

    Cool :D One module goes trash bin :)

    Thanks

  4. Dawood
    Permalink to comment#

    Great !!!

Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

```
<script>
  function example() {
    element.innerHTML = "<div>code</div>";
  }
</script>
```