How To Add Gravatars For The Post Author in WordPress

Now that Gravatar support is part of the WordPress core adding them into your WordPress theme is easy. Adding them to your comments has been documented. How about adding them to your post titles to highlight the comment author? Within the loop? That’s fairly easy too. Here’s the code:

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

Pretty simple, huh? get_the_author_email outputs the post author’s email and the “80″ is the size of the avatar image in pixels (you can change that). How this will look depends on how you use it; where you put it in the theme (it has to be in the loop!) and how you style it.

Want an example? I had to figure this out for an upcoming project so…

Author Gravatar Example

Look at that frighteningly intense young man there in black and white. Good grief, it’s me! The author of the post! The code, it works! It works!

Ahem. Excuse me. I get a little excited about these things. Good luck using it in your own theme!

By the way, did you know WordPress has built in email protection from spam bots (read Disguising Your Email)? I didn’t. Neat.

162 thoughts on “How To Add Gravatars For The Post Author in WordPress

  1. That’s pretty cool Ian. I enjoying reading your WordPress tips and your new Amazon bookstore looks cool. I gotta find some time to read your creative thinking recommendations.

  2. Pingback: How To: Adding the Post Authors Gravatar To Their Individual Posts

  3. Cool! I love the idea. I’ve seen some sites with the author’s avatar right after the post but isn’t this gravatar thing more applicable in a multi-user blog?

  4. Pingback: Ultime dal fronte WordPress 18-2008

  5. Pingback: WordPress Weekly News, 18-2008

  6. Pingback: FearlessFlyer.com » SimpleSkin Wordpress Theme

  7. You’re totally talking about my latest theme. I implemented this technique in WPFreemium but instead of using the author’s email, I used their ID e.g. “the_author_ID();”.
    It took me hours trying to find out how this worked at first since I couldn’t find any documentation in the codex I had to dig into the core files.

  8. The theme you’ve come up with is a great example what I’ve outlined, Ptah. Very cool.

    And it’s totally frustrating when you know, in theory, you can do something and quickly realize you’re going to have to figure out how to do it yourself. Except of course when you figure it out. Then, well, that’s awesome. :)

  9. mark says:

    hai ian, can you point which specific place to put the code, because i have not found where the loop is? in comment.php, single.php or where?

  10. Pingback: élet és könyvtár » Blog Archive » Szerzői avatarok a címek mellett

  11. Pingback: How To: Adding the Post Authors Gravatar To Their Individual Posts | [Blog Tutorials]

  12. Pingback: 40+ Most Wanted Wordpress Tricks and Hacks

  13. Pingback: 40+ Most Wanted Wordpress Tricks and Hacks | 胡作非为 - 每天精彩文章推荐 - Best Articles of the Day

  14. Pingback: 30个优秀Wordpress技巧

  15. Pingback: 30个优秀Wordpress技巧 | Yansen's Blog

  16. Pingback: 30个优秀Wordpress技巧 | 半瓶可乐

  17. Pingback: 激战的人生 » Blog Archive » 30个优秀Wordpress技巧

  18. Pingback: WP.ORG.CN | 30个优秀的Wordpress技巧为您打造强大的博客

  19. Pingback: 我要当站长–51dzz.com » 30个优秀Wordpress技巧

  20. Pingback: 米老虎的BLOG » Blog Archive » 40+最有用的WordPress技巧

  21. Pingback: 用友资讯 » Blog Archive » 30个优秀Wordpress技巧

  22. I still don’t understand exactly where i’m supposed to place the code. Where should i put it if i want it to look like in the picture? could you please show me?

  23. Ok thanks for the quick reply

    I really don’t know much CSS, but i just discovered that the theme i use, apparently has a single php file for most of the loop stuff… Im going to try to mess around with that, ive managed to do a lot by trial and error before…

    By the way do you have any idea how i can find the part of the code that shapes the post headline area? like specific terms to search for or something. I also need to change the color of the headlines themselves, but thats probaly somewhere else…

  24. Pingback: PP BLOG# » Blog Archive » 30个优秀Wordpress技巧

  25. Pingback: 9月森林 » 40+ Most Wanted Wordpress Tricks and Hacks

  26. Pingback: Más de 40 consejos y trucos para Wordpress

  27. Pingback: 30个优秀Wordpress技巧 - 网络应用与资讯

  28. Pingback: 40 consejos y trucos Wordpress para dar a tus proyectos aspectos realmente diferentes. « Xyberneticos

  29. Pingback: 40 consejos y trucos para Wordpress | aNieto2K

  30. Pingback: 40 самых востребованных настроек/доделок/хаков для WordPress

  31. Pingback: 40 Consejos y trucos para WordPress

  32. Pingback: 40 trucos muy buenos para wordpress | Wotevar

  33. Pingback: Mas de 40 trucos y hackeos para Wordpress | Pboza

  34. Pingback: 40+ Most Wanted WordPress Tricks and Hacks | Blogging Tips

  35. Pingback: 40 Consejos para optimizar tu Wordpress » Comenta o Muere | Actualidad, Humor, Tecnología, Política, Ciencia, Música… y otros muchos temas de los que merece la pena hablar.

  36. Pingback: Dicas para você melhorar seu Blog - WordPress | DanielCamargo

  37. Pingback: Cosas por hacer luego de instalar Wordpress | Durmiendo Afuera

  38. Pingback: vsFish » 30个优秀Wordpress技巧

  39. Pingback: 41 trucos y consejos para Wordpress « Helektron.com

  40. Pingback: Antibioticos « SoLo Se Que No Se NaDa

  41. Pingback: 鱼鱼小札 » Blog Archive » 30个优秀Wordpress技巧

  42. Pingback: 30个优秀的WordPress技巧 | 智康博客--个人日记|网络技术|免费分享|技术交流|WordPress学习

  43. Pingback: 30个优秀的Wordpress技巧为您打造强大的博客 | abe design studio

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s