Identify Authors With Gravatars


Since WordPress version 2.5, it is easier to include the Gravatar of a comment author in the comments. WordPress offers a feature that is easy to use and it brings some parameters with. In order to use and how to include a Gravatar, I would refer to the article „Gravatar Use Easy“.

But with this feature you can do more. Magazine-style for blogs are currently in high demand and many blogs have a a couple of authors. Many times the blogs link and present the author of the respective contribution. WP offers a whole range of template tags to this functionality, check out Codex.

Now it would be nice to give the author a face. You can do that with the Plugin „Extended User Profile“ and enter more information in the backend of WordPress.

Alternatively you can load the Gravatar of the author. The Gravatar function get_avatar() works great in the loop of WP and you just have to assign the email address. It's easily done by the template tag get_the_author_email().

<?php
$author = get_the_author_email();
echo get_avatar( $author, 80 );
?>

This above code creates this:

<img alt='' src='http://www.gravatar.com/avatar/md5-Schlüssel_des_gravatar?s=80&d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fmd5-Schlüssel_des_gravatar%3Fs%3D80&r=G' class='avatar avatar-80' height='80' width='80' />	

Alternatively you can get the email directly, with any variables.

<?php echo get_avatar( get_the_author_email(), 80 ); ?>

Use CSS to format, you can use the class avatar, which is also assigned to the comments. Simultaneously there is also a class, which is created in regard to the Gravatar size, for the above syntax it would be avatar-80. So it's possible to format the picture of the author with this class.

Comments are closed.

12 comments

  1. Lilly

    Hi, just a quickie to say thanks for this post. Instead of pumping out yet another silly wordpress plugin does something really simple, your posted this wonderfully straight forward post that answered all my questions quickly and sweetly. So, thanks :)

  2. Alex

    Our pleasure Lilly :)

  3. ragi

    Thanks!!!!! :)

  4. azril

    Nice info. Trying to get gravatar in my comments page

  5. ebusinessmom

    Thanks for this post. I've been updating gravatar options on my blog with not much to go on. I'm learning every single day how to make every aspect of my blog much better for my readers, and ugly default gravatars was one of my problems. Thanks again for the tips that I'm working on implementing.

  6. Jacob

    Ahh! This is great, I was searching for a good 30 minutes before I stumbled across this page. I'd already tried a few plugins but they were all too bulky, this is perfect!

  7. M. Lucarelli

    I thank you very much for that! Congratulations!!!
    Simple and perfect!
    Best regards!

  8. LB

    Alex, any way you know of to get that same thing on the main homepage with each excerpt? i know this might vary based on theme, but anything might help. Thanks.

4 pingbacks

  1. How to: Add author’s gravatar in posts
  2. 30 Most Wanted WordPress Comments Page Hacks | instantShift
  3. 30个你最想要的Wordpress回复页技巧 - 落落寡欢
  4. 30个增强Wordpress留言部份的技巧 | 帕兰映像