As we continue to gear up for WordPress 2.5, have you gotten your theme ready for Gravatars? In the past it required plugins, but now WordPress 2.5 has built-in Gravatar support. This means going forward, themes can easily be released with Gravatars built-in to the theme because no plugin will be required.

So, you’ve got WordPress 2.5 installed and you’re ready to assign Gravatars to your comments? All you need to do is a quick code hack to the comments loop where you want the Gravatar to show up:

<?php if(function_exists(’get_avatar’)){ echo get_avatar($comment, ‘50’);} ?>

I encourage everyone to support WordPress by displaying Gravatars on their blogs once you’ve upgraded to WordPress 2.5.

Kyle Eslick is WordPress enthusiast who took his passion for WordPress to the next level in 2007 by launching WPHacks.com as a place to share hacks, tutorials, etc. Connect with Kyle on Twitter or Google+!

  1. bardo says:

    Thanks for that.
    What about placing it anywhere outside of the comments loop? I’d like to put it on my index page, in a header, close to the navigation menu, for example..

  2. Since you asked, I have modified by theme to include them at:

    http://www.macnightowl.com

    Peace,
    Gene Steinberg

  3. Kyle Eslick says:

    @ Bardo – You should be able to use the code wherever you want to display a Gravatar, as long as there is an e-mail address assigned to the post/sidebar, etc. (Like an About Author section, etc.)

    @ Gene – I checked it out and it looks great!

  4. Thank you. It took all of a minute or so add the code to each of my comments files (the site is made up of two integrated blog installations). And I don’t speak PHP.

    Peace,
    Gene

  5. wOw!bloggiNE says:

    I’m Vietnamese. I don’t speak well English.
    Can you help me ? I don’t know.
    Where can i place code ? in comment.php? i want it’s showed in right comment same you
    and code of recent comment in your sidebar is great. Can you share it ?

  6. Kyle Eslick says:

    @ Wow – Yes, place it within your comments.php file wherever you want it to display. If you dig through the code, you should see some things you recognize from your comment layout, so that is an easy way to figure out where to place the code. You may have to experiment until you’ve got it in the right spot.

  7. Joni Solis says:

    Sounds so easy to do, but after 30 minutes of trying I still couldn’t get an gravatar image to show up in my blog’s comments. I tried putting the code from this post in a whole lot of different spots in the comments.php file but all it did was cause my post to show no comments at all and not load right.

    Can someone pin point exactly where in the comments.php file this code goes? I have the WordPress Theme Almost Spring.

    By the way, what WP plugin are you using for your email notify of comments. Thanks!

  8. Jauhari says:

    Let’s me tested and give you a feedback

  9. Joni Solis says:

    Is there a WordPress Plugin that put this text:

    [Want automatic updates? Subscribe to our RSS feed or Get E-mail Updates Automatically!]

    At the bottom of each post? What is the name and the URL where I can get it and does it work with WP2.5?

    Thanks!

  10. Joni Solis says:

    For anyone having trouble (like me) adding gravatar images to their comments. I went and installed the WordPress plugin…

    Easy Gravatars
    http://wordpress.org/extend/plugins/easygravatars/installation/

    Easy Gravatars 1.2
    http://dougal.gunters.org/

    Add Gravatars to your comments, without requiring any modifications to your theme files. Just activate, and you’re done! By Dougal Campbell.
    —-
    Now I have gravatars images, yea!

  11. MhawSayar says:

    It’s one of the great function of WP 2.5. I love it too and thanks for sharing knowledges! :)

  12. bienB says:

    Gracias por la informacion, pero ¿como puedo crear un avatar?

  13. HEdi says:

    It shows me an error when I insert that line of code you gave:

    Parse error: syntax error, unexpected ‘)’ in /home/macamour…./comments.php on line 98

  14. Hayes Potter says:

    I uploaded a picture of me to my wordpress.com account, that I have my blog registered under. My wp.com profile has the same email address as the one I use everywhere. But my gravatar will never show up on any blog. My username for wp.com is hayesp could that effect anything?

  15. David says:

    Whew, been trying to find out how to do this. Gave it a try, and…well…it works. :)

    Definitely adding this site to my WordPress-related bookmarks. I’ll be sure to post questions or so if the need arises.

  16. DazzlinDonna says:

    There is an error in that code. The ? after the 50 should be a single quote, not a ?.

  17. Kyle Eslick says:

    @ Dazz – Thanks. I have corrected the code in the above post. Hopefully that will fix any of the errors listed above.

    @ Joni – That is the Subscribe to Comments plugin. Do a Google search and it should be the first one that shows up. The text I use at the bottom of each post is not a plugin, it is just basic HTML with a link to both subscription options. You can add it just below the content in your single page file.

    @ Hayes – You need to sign up at Gravatar.com to get your Gravatar.

  18. teguh says:

    Thanks for your post..it’s work, thanks

  19. kamal says:

    This is just awesome.You helped me a lot!Thanks.

  20. Thank you very much for the awesome post. It’s really works!

  21. khan says:

    i have tried several times but it is not workin…

  22. Dan says:

    Yo can easily put Gravatars anywhere, I use them in a drop-down nav menu – tutorial here – http://hygen.net/blog/?p=427

  23. Alex says:

    Hey, thanks for the code but a quick heads up.

    The code snippet above has curly quotes around ‘get_avatar’ and ’50’ which will break it for copy and pasters.

  24. Rollins says:

    Nice.

  25. Thanks! I’ll have to try this asap.

  26. Msuvain says:

    Will the 2.5 function automatically hash the lowercase version of the email address? This seems to be a persistent issue, with users leaving mixed-case version of their email address with their comments.

  27. J. Guimarães says:

    I like this idea.

  28. Already installed on my blog.
    I really enjoyed.

Trackbacks/Pingbacks »