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!

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

    Cool :D One module goes trash bin :)

    Thanks

  4. Dawood
    Permalink to comment#

    Great !!!

Leave a Comment

Posting Code

  • Use Markdown, and it will escape the code for you, like `<div class="cool">`.
  • Use triple-backticks for blocks of code.
    ``` 
    <div>
      <h1>multi-line block of code</h1>
      <span>be cool yo.</span>
    </div>
    ```
  • Otherwise, escape your code, like <code>&lt;div class="cool"&gt;</code>. Markdown is just easier though.

Current ye@r *

*May or may not contain any actual "CSS" or "Tricks".