Filosofo’s WordPress Gravatar Plugin

Automattic, the company behind WordPress, recently acquired Gravatar. In case you don’t know, gravatars—or “globally recognized avatars”—are images that you can associate with an email address, so a picture of your choice can appear alongside your comments on many others’ blogs.

Gravatar already provides a simple WordPress plugin, but it suffers from a common plugin problem: if you add its “gravatar” function to your comments template, you either have to wrap it in a function_exists check, or you’ll get a fatal error when you deactivate the plugin.

My gravatar plugin lets you use WordPress’s action hook callback system, so it just disappears when the plugin is deactivated.

How it works:

  • If you just want to display a commenter’s gravatar image, just add


    <?php do_action('gravatar') ?>
     

    to the appropriate place in your WordPress comments.php template. By default, it will generate a gravatar image.

  • But you can customize it as much as you want, by passing an array of arguments to the ‘gravatar’ action hook. On my blog I’ve done the following:


    <?php do_action('gravatar', array('div_class' => 'gravatar', 'return' => 'div', 'default' => get_bloginfo('stylesheet_directory') . '/images/default_gravatar.png', 'rating' => 'PG')) ?>
     

    That tells the plugin to wrap the gravatar image in a div with a class of “gravatar”, using a default gravatar image located in my theme’s images directory, and returning only PG-rated gravatars.

    Here is a complete list of arguments you can pass to the gravatar hook:

    • alt: Text for the alt attribute of the gravatar image.
    • border, b: An argument you can pass to the gravatar server, the “border” is a hex color to be generated around the gravatar image.
    • comment_author_email: The email on which to base the gravatar. By default, the plugin gets this from the comment’s author email.
    • default, d: The default image to use if no gravatar is available.
    • div_class: A class for the div element surrounding the gravatar, if you’ve set “return” to “div.”
    • echo: Whether to echo the result (true by default). If you wanted to assign the gravatar image URL to a variable named $path, you would do the following:

      <?php $path = apply_filters('gravatar', array('echo' => false, 'return' => '')); ?>
       
    • gravatar_id, g: The gravatar id. Usually this is generated from the commenter’s email, but if you want you can pass it directly.
    • img_class: A class for the gravatar img element.
    • rating, r: The rating of allowed gravatar images, as explained at the gravatar website. Optinos are G, PG, R, and X.
    • return: What to return. By default, this is an image element (“img”). You can also select “div” for a div element around an image, or just return the path to the image with “return” set to “”.
    • pattern: Any string containing %s; the plugin will return that string, replacing %s with the gravatar image path.

      For example, setting “pattern” to would return the gravatar image in a span element.

    • size, s: The size of the gravatar image, in pixels. Currently it can range between 1 and 80.
  • Download

    Filosofo Gravatar Plugin 1.5 | March 15, 2007

    If you have problems, questions, or suggestions, please leave a comment below or open a ticket in my support forum.

    See some of the other WordPress plugins I’ve created.
    Like this plugin? Is it worth a latte?

    My Amazon.com Wish List

    This month I have received $31.50 in donations for the free plugins I offer here, which is about $0.01 per download.

79 Comments

  1. Great plugin. Thanks for release this.

  2. I’m having the damndest time trying to figure out how to make the gravatars smaller. I’m using a css stye of:

    .gravatar { float: right; padding: 4px; margin: 0 0 2px 7px; display: inline; }

    When I enter a value of “height: 60 px; width 60 px” nothing seems to change. What am I doing wrong?

    Thanks.

  3. Thanks for making it easy to support Gravatars on WordPress.
    The plugin works great. I ended up customizing it using this code.
    < ?php do_action('gravatar', array('div_class' => 'gravatar', 'return' => 'div', 'default' => get_bloginfo('url') . '/images/gravatar.jpg')) ?>

    Thanks

  4. Rick, I’d forgotten to include in the description of the API that you can select the size of the gravatar that you want. For example, the following would return gravatars of size 60 pixels:

    < ?php do_action('gravatar', array('size' => 60)) ?>

  5. The following doesn’t appear to work for me when reducing the size of the avatar:

    60, ‘div_class’ => ‘gravatar’, ‘return’ => ‘div’, ‘default’ => get_bloginfo(‘/wp-content/themes/hight-tech-10/hight-tech-10/style.css’) . ‘/images/default_gravatar.png’)) ?>

    What part of the code is incorrect?

    Also, and I realize this is more of a design question, but how do I make sure the box around my comments accounts for the image and goes around the image too? On some of my shorter comments, the bottom of the avatar hangs below and outside of the box around the comments.

    Thanks


  6. What part of the code is incorrect?

    It looks like you’re missing the first part of your code. Try pasting it again, this time putting it between <code> tags.

    Also, and I realize this is more of a design question, but how do I make sure the box around my comments accounts for the image and goes around the image too?

    Here is the classic advice on how to clear a float.

  7. Wow thats one pretty cool tweak. I really like the ability to change the size. I’ll try it out on a sports blog.

  8. Great plugin, thank you… :)

  9. This would be a bit more user friendly if the arrays were configurable options in the form of checkboxes or text fields in the admin panel. If your a non programmer, this code is a bunch of trial and error to get it to work right.

  10. Nice plugin, thanks

  11. I am use it and really happy with it, thanks

  12. Hiya,

    Im also using Filosofo Gravatars and after managing to fiddle around with the options its running nicely.

    BUT its missing a feature:
    Whenever a comment is created by a trackback or pingback, it should not display the gravatar. I dont have comments and track/pingbacks separated and my theme doesn’t seem to support plugins doing so (and I guess there are other ppl with the same problem). I’d really appreciate a plugin update ;)

  13. Will try this at my site later today!

  14. Hmmm..my picture doesn’t appear here either. Do I need your plugin and the gravatar plugin both?

  15. Figured it out. Is this array(‘size’ => 60) a second array or is this ‘size’ => 60) inserted after a comma after another argument? (Not a coder.) I tried a comma after ‘PG’ and inserted the size argument but caused the page to stop writing before the comment box. This works: ‘gravatar’, ‘return’ => ‘div’, ‘default’ => get_bloginfo(‘stylesheet_directory’) . ‘/images/popw.gif’, ‘rating’ => ‘PG’)) ?>

    Just not sure where the size code goes.

    Great plug in.

  16. The size is part of the rest of the array, so you could do something like this:

    < ?php do_action('gravatar', array('div_class' => 'gravatar', 'return' => 'div', 'default' => get_bloginfo('stylesheet_directory') . '/images/default_gravatar.png', 'rating' => 'PG', 'size' => 60)) ?>

    I know it’s not incredibly user-friendly, but I really wanted something lightweight and straightforward. The other Gravatar plugins are bloated, in my opinion.

  17. I’ve actually created a Gravatar class if you click the link in my name. Loosely coupled and works like a dream – it also has a cache with an expiration date for the avatar – to save on loading times. It can merely load the avatar in locally.

    Adam @ TalkPHP.com

  18. Works perfectly. Thanks!

    Now if only they’d create a WordPress.com Avatar API so we could grab those too.

  19. I’m only able to see the default gravatar icon for some reason.

    Could it be because I’m using the Co-Authors plugin?

    Thanks much,
    Andy

  20. working now — i think it must have been a delay on gravatar’s server. thx.

  21. Great plugin! Now I just have to figure out how to get it working :)

  22. I cannot get the gravatar images to show up. Do I need something besides this file…
    filosofo-gravatars.php
    placed here:
    /httpdocs/blog/wp-content/plugins/

    and this code:

    placed in this file…
    blog\wp-content\themes\blix\comments.php

    I need help with this. Can I pay you?

  23. Oops, the code disappeared.
    here it is again…(I forgot to enclose it with the code tags)

    < ?php do_action('gravatar') ?>

  24. Is there an easy way to eliminate the default image entirely, leaving only an empty space w/o image tags for commenters not registered with gravatar?

  25. hi. Thanks for plugin

    perfect.

    regards

  26. Hi Filosofo,
    your plugin sounds great but I can’t make it work. I placed the simple code on different places in my comments loop but it never shows anything up. Could you please help me out and tell me where I should place it ?
    Thanks !

  27. Hem, ok I’ve found : I hadn’t activated the plugin…

  28. HI,

    i want to replace the default image, if someone has no gravatar (the grey guy), with my own image.

    Is that possible with your plugin or do you have a workaround for it? I use WP 2.7.1 btw :)

  29. @Tari: You can set the default image with the “default” argument (see above).

    Currently I have “default” set to “identicon,” but in the past I’ve used something like the following line:

    <?php do_action('gravatar', array('default' => get_bloginfo('stylesheet_directory') . '/images/default_gravatar.png')) ?>

  30. The plugin works great.

    However, I’d like to position the gravatar to the left of my comments. But I don’t have a clue about how to do this.

    Can you please help?

    -jens

  31. Hi. Not sure exactly where to add the php do_action(‘gravatar’) ?

    The loop code looks like this:

    foreach ($comments as $comment) {
    $output .= “\n
    “.”ID) .
    “#comment-” . $comment->comment_ID . “\” title=\”on ” .
    $comment->post_title . “\”>” .strip_tags($comment->comment_author)
    .”: ” . strip_tags($comment->com_excerpt)
    .”…

    Any ideas?

    Thanks,
    David

  32. Sounds like a great plugin, but I cannot make it work.
    I’ve activated the plugin, uploaded the image under the theme imaages folder and added this in my comments.php editor:

    ‘gravatar’, ‘return’ => ‘div’, ‘default’ => get_bloginfo(‘url’) . ‘/images/default_gravatar.gif’)) ?>

    I’ve also tried:

    ‘gravatar’, ‘return’ => ‘div’, ‘default’ => get_bloginfo(‘stylesheet_directory’) . ‘/images/default_gravatar.gif’)) ?>

    but unfortunately these codes are for me chinese… could u pls tell me what I’m missing?

    Thanks!

  33. Aljaz, take a closer look at the example code: you’re missing array( in a key place.

  34. OK good to see- interesting blogs are always sweet! Peace.

  35. Excellent site. Lots of useful information here. I’m sending it to a few friends ans additionally sharing in delicious. And naturally, thank you in your effort!

  36. Interesting and communicative.

  37. everyone will like this article……

  38. I agree with you, very nice

  39. the language is straightforward, complete, concise, so I can understand on this article…
    thanks,,,

  40. Very interesting your posting, thanks for putting up.

  41. While I don’t use WordPress, I know a number of other bloggers that do, so this is great to pass along to them. Thanks!

  42. so much wonderful information on here, : D.

  43. Very interesting your posting, thanks for putting up.

  44. An discussion you can successfully pass to the gravatar server, the “border” is a hex shade to be produced around the gravatar picture. bubblegumcasting

  45. My gravatar plug-in allows you use WordPress’s activity connect callback program, so it just vanishes when the plug-in is deactivated. martin backpacker guitar

  46. This 30 days I have obtained in contributions for the 100 % free plug-ins I provide here, which is about $0.01 per obtain. montague bike

  47. This is very handy, thx for sharing this, much appriciated!
    cazare Mamaia

  48. Congrats, there are only few lucky kids who got such a wonderful blogs dedicated to them. I would love to set up such a lovely blog for my kid in India also.

  49. Buddhism understands of that from the perspective of ego the opportunities of lack of way of life is generally difficult. westchester wildlife removal

  50. Well Lots of useful information here. I’m sending it to a few friends ans additionally sharing in delicious. And naturally, thank you in your effort! Accident Claims

  51. it’s really nice and meanful. it’s really cool blog. Linking is very useful thing.you have really helped lots of people who visit blog and provide them usefull information. xjming.com

  52. Thanks to an variety of cell phone applications and reasoning processing, companies can often find out most of the details they need, and manage their day, without ever speaking with the home company office. Expensive Handbags

  53. wrap it in a function_exists check, or you’ll get a fatal error when you deactivate the plugin.

  54. We work in some dynamic, information-hungry markets that behave completely differently from more mature markets. about our company

  55. I was able to finish a picture venture I had been operating on! It also turns the offering slots when they put enough weight on the band. It was much more realistic. agen bola online 

  56. Sorry to listen to about your encounter with melanoma. Seems like an odd place to. click here to investigate

  57. I am always searching online for articles that can help me. There is obviously a lot to know about this. I think you made some good points in Features also. Keep working hotties

  58. Trouble Spot Training review, ebook FAQ, and PDF download guide that provides an insider’s look at the program and answers frequently asked questions about Bruce Krahn’s unique and highly popular body transformation guide. No Win No Fee

  59. You will be on an adventurous ride when you want to be successful at making money online No Win No Fee Claims

  60. We can still make very healthier earnings while preventing bankrolling financial and environmental destruction – and we can information up all these clients. important site

  61. We can still make very healthier earnings while preventing bankrolling financial and environmental destruction – and we can information up all these clients

  62. Well another way to increase the level of intensity within the game, now that you can have at most sixteen players playing side by side or competing against one another. No win No Fee

  63. very isolated islands is home to some of the largest populations of seabirds in the world, one seabird in particular called the Albatross. Every year the Albatross use Midway Atoll as their main nesting place for thousands of tiny baby Albatross chicks but this overwhelming action of life and birth is met harshly by the massive death and sadness. No Win No Fee Claims

  64. Well just looking around some blogs, seems a pretty nice platform you are using. I’m currently using WordPress for a few of my sites but looking to change one of them over to a platform similar to yours as a trial run. Medical Negligence Solicitors

  65. From the onslaught of the internet, to digital cameras to even very powerful camera photos, this new creative landscape is not in the textbooks nor is it in the old school knowledge of photography Medical Solicitors

  66. Every year the Albatross use Midway Atoll as their main nesting place for thousands of tiny baby Albatross chicks but this overwhelming action of life and birth is met harshly by the massive death and sadness. the venus factor does it work

  67. Although many had filled to their first surfaces, unfortunately, a threat that comes from residing near the seaside and, again, not a nationwide catastrophe. Sell your home fast

  68. I will be interested in more similar topics. i see you got really very useful topics , i will be always checking your blog thanks.

  69. I really had fun while reading this article and I think that everything here is really greatly published and I also think that this can be one of the best articles of all time! PPI Claims

  70. this is just magnificent! I have encountered yet another one of your magnificent articles. I just don’t get how can you be so consistent in your quality of articles net

  71. Thanks for your post. I’ve been thinking about writing a very comparable post over the last couple of weeks, I’ll probably keep it short and sweet and link to this instead if thats cool. Thanks. Flight Delay Compensation

  72. This knowledge.Excellently written article, if only all bloggers offered the same level of content as you, the internet would be a much better place.

  73. Thank you for this post. That’s all I are able to say. You most absolutely have built this blog website into something special. You clearly know what you are working Medical Negligence Claims

  74. Well really make it seem so easy with your presentation but I find this topic to be really something which I think I would never understand. It seems too complicated and very broad for me. I am looking forward for your next post. Compensation For Delayed Flights

  75. I sincerly thank you for spreading and sharing your valuable knowledge and information, which many less people do these days!

  76. aprender los fundamentos del dise?o del juego o la programaci?n inform?tica .
    Hoy ,muchos jugadores se aprovechan de la existencia de gr?ficos,sprites y motores de juego where to buy citrol degreaser

  77. Nice quality writing! The conclusion is very much fine and grabbed the attention. I hope to read more through you. vliegenlamp

  78. Oh man, I’d completely forgotten about Powder. But this video brought it all back. Pun not intended. browse around this site

  79. Good Topic! Thanks for the post author,Bookmarking your page!

Post a Comment

Your email is never shared. Required fields are marked *

*
*

30 Trackbacks