post-page

Gravatars and WordPress 2.5

98
responses
by
 
on
March 3rd, 2008
in
HOW-TO, WordPress

Several commenters mentioned on yesterday’s post regarding Gravatars without a plugin that WordPress 2.5 would be having built-in Gravatar support.

And indeed WordPress 2.5 will come with Gravatar (aka, Avatar) support. Within this post I will demonstrate how Gravatars will be used with WordPress 2.5. As a side note, 2.5 has yet to be released as of this writing.

Gravatars in the WordPress Admin Panel

WordPress 2.5 marries theme authors and casual WordPress users together with support for Gravatars in the WordPress admin panel.

WordPress users can access the Gravatars settings in the Settings->Discussion panel.

If a theme author has decided to use the WordPress 2.5 function, then WordPress users can easily control their Gravatar usage in the admin panel.

In the admin panel, WordPress users can change:

  • Whether Avatars (aka, Gravatars) are displayed or not.
  • Which rating of Avatars are shown.

avatar_admin_panel.jpeg
Avatars in the WP Admin Panel

Please keep in mind these settings will have no effect if the theme author didn’t make use of the WordPress 2.5 function.

And what is the functon you ask?

Theme Authors: Adding Gravatars to Your Theme

The function to add Gravatars to your theme is called: get_avatar. The function returns a complete <img> tag of the Avatar.

The function get_avatar is setup as follows:

function get_avatar( $id_or_email, $size = '64', $default = '' )

  • id_or_email: The author’s User ID (an integer or string) or an E-mail Address (a string)
  • size: The size of the Avatar to display (max is 80).
  • default: The absolute location of the default Avatar.

Some things to note here:

  • The default Avatar size is 64×64.
  • The default Avatar is Gravatar
  • The Avatars will show only if the user allows them in the WP Admin Panel (enabled by default).
  • The Avatars will only show based on the rating the user has selected in the WordPress admin panel.

Here are some examples of the function in use:

Example 1 with a default Avatar

echo get_avatar( 1, '80', 'http://mysite.com/avatar/avatar.gif' )

In this example I used a user ID of ‘1‘ and specified the location of a default location. This example is useful if you want to display an Avatar outside of the comment’s section and you have an idea of the person’s User ID.

Example 2 with an e-mail address and size

echo get_avatar( 'myname@mysite.com', '60' )

This example is useful if you want to display the Avatars within the Comments Loop.

If calling Avatars from the Comments Loop (in comments.php), you will want to use the get_comment_author_email function in place of the above e-mail address.

echo get_avatar( get_comment_author_email(), '80' )

Backwards Compatibility

If you wish to develop a theme that displays Avatars for 2.5 and below, I recommend using a combination of the code mentioned here and the code from Connor Wilson’s post on using Gravatar without a plugin.

Your code would look something along the lines of:

if (function_exists('get_avatar')) {
 	//2.5 code
 } else {
 	//alternate gravatar code for < 2.5
 }

Further Reading

For more reading on the get_avatar function, please read Ryan Boren’s Avatars in WordPress 2.5, which he covers several additional points not mentioned here.

Conclusion

The inclusion of the get_avatar function is a nice addition to WordPress 2.5, but it relies on theme authors to include it. If you are comfortable editing your own theme, you can easily add the function into your own theme when 2.5 is released.

heading
98
Responses

 

Comments

  1. Small Potato (19 comments.) says:

    Thanks Ronald. I need this to prepare Wpdesigner.com’s themes for 2.5.

  2. Ronald Huereca (39 comments.) says:

    @Small Potato,

    You’re welcome. This post was written for theme developers like you. Hope all goes well on your front.

  3. michael lee (9 comments.) 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.

  4. Ronald Huereca (66 comments.) says:

    Michael,

    It does do a lowercase version from what I can see.

  5. Jeff (11 comments.) says:

    Gravatars are part of the WP Core now? I know Automattic is running them now, but why isn’t this feature a plugin like Akismet? Seems counter to other running philosophies. :/

    • Mike (3 comments.) says:

      I don’t think it is. I mean, gravatar has been bought by WordPress, but to display it, you have to use code or so.

  6. Alex :: Web Design (5 comments.) says:

    @Jeff – I reckon though that because you can turn it off, it is like using a plugin, you aren’t forced to use it, but so many people do that I guess it was deemed useful to have it in the core.

    I’ve personally never used them, but who knows, maybe this will be what I need to start!

  7. Deddy says:

    Wow, this would be great! Thanks…

  8. Benedict Eastaugh (17 comments.) says:

    As I understand it, they were added into WP core not merely because this is an oft-requested feature, but also because theme and plugin authors can override the function in order to pull in avatars from sources other than Gravatar.

    In other words, while it defaults to using Gravatar, it’s more generic than that: it’s a WordPress avatar API, not a way of tying all WordPress users and developers into a proprietary service.

  9. Ronald Huereca (66 comments.) says:

    @Benedict,
    Yes, the function is pluggable, so it can be used with other services. Thanks for bringing that up.

  10. Scyfox (2 comments.) says:

    Nice.

    Also i liked to be able to show a gravatar outside the loop.

    Nice tips.-

    Silla!

  11. bubazoo (213 comments.) says:

    So, I am confused.. So, is the Gravatar system in WP 2.5 similar to that of http://site.gravatar.com/ or is it going to be a completely new rewrite?

    reason I’m asking, is because I can’t see WP users wanting to upload an avatar to every blog they visit, and since the gravaar.com method has been a little “flaky” as of late, is wordpress planning on integrating it into the wordpress.com API? or with gravatar.com, or both or what? I am confused as to what this means

  12. bubazoo (213 comments.) says:

    in either case, I think this is a smart move, because the gravatar.com service doesn’t work 90% of the time, or the gravatar plugins they do have for wordpress don’t work 90% of the time. It drives me nutts, because my gravatar NEVER works on anyone elses site but mine, so I take it up with the plugin authors and they blame gravatar.com, so I take it up with gravatar.com and they say its the plugin authors fault. arrgh. its frustrating, so however WP plans on doing it, is a very very good thing, FINALLY gravatars may actually WORK in wordpress thank the good lord. hehe

  13. Stasmi says:

    This sounds very exciting. You all are doing a great job. I can’t wait for 2.5!

  14. Jason DeVelvis (9 comments.) says:

    Ronald,
    Perfect timing for posting this – I hadn’t heard they were adding gravatar support in 2.5, so I had made my own function. But now I can cut my plugin size and use the Avatar API.

    Thanks for the heads up!

  15. Ronald Huereca (66 comments.) says:

    @bubazoo,

    Gravatars, Avatars, whatever you’d like to call them, are using the Gravatars site. The main thing is that the core code now contains the function to retrieve the Gravatar rather than relying on a third-party plugin.

    I imagine a lot of the times the Gravatars don’t work because of case issues, trim issues, or perhaps in my case I use a variant of my original e-mail address. Gravatars have improved significantly since Automattic took over them.

    @Jason,
    You’re function will still be useful for blogs < 2.5.

  16. Edward (4 comments.) says:

    Can’t wait to see WP 2.5!

  17. Jason DeVelvis (9 comments.) says:

    @Ronald
    Yep, I re-read your post after I made that comment, and saw that part in there – Thanks!

  18. Dawn (2 comments.) says:

    I’m using the “gravatars with a plugin” code on my website, it almost works.

    I am registered with grvatar and my gravatar doesn’t show, I’m looking forward to trying the functionality in 2.5.

    http://blog.yourwish.co.nz/200.....dding-day/

  19. CA RO says:

    I’ve tried the function, cant make it work, the encoded email is not md5 as md5(“email”) dont know why looking for the function now

  20. kartz says:

    good feature but we are expecting more from wordpress next stable releases…..

  21. Dawn (2 comments.) says:

    User error, its all working perfectly, though I am looking forward to trying out the built in gravatars in 2.5.

  22. rayk (3 comments.) says:

    Just found this article, thanks for the heads up! Gotta update my theme and test it with RC1

  23. Zeus says:

    This is very, very nice =)

  24. zombified (1 comments.) says:

    I want to add a little update here. I searched a lot but couldn’t find the gravatar option in WordPress 2.5. After some more searching, I found it isn’t on the reading panel, but it’s on the discussion panel. Maybe you can edit the post and update this.

    Thanx fot the the great blog you’re running, it’s my number one source for wordpress :)

  25. uncalau says:

    “WordPress users can access the Gravatars settings in the Settings->Reading panel”

    I find this misleading… the Gravatars setting is in the SETTINGS -> Discussion panel (scroll to the bottom) instead.

  26. Ronald Huereca (66 comments.) says:

    Thanks guys. Post has been updated. When I wrote it, it was in the Reading panel. As WP 2.5 was released, it was moved to Discussion.

  27. tm says:

    Well I got it working. Now I just need to get it working with Comvatars. It looks like the upgrade broke that plugin.

  28. Ducked.nl (1 comments.) says:

    Gooed piece of information, I had to find it out own my own to made it work on my blog here.

    I finally made use of a plugin ;)

  29. Web Design Manager says:

    What is the difference between Gravatars and Avatars, I mean the key factor. No one can answer me.

  30. Ronald Huereca (66 comments.) says:

    @Web Design Manager,

    Gravatars are the same as Avatars. There is no difference.

    Gravatars stand for Globally Recognized Avatars. GR-Avatars.

    Any system that utilizes the Gravatars API will be able to pick yours up from your e-mail address.

  31. ?? (1 comments.) says:

    ??????????? CJ?? http://www.8cj.cn

  32. tom says:

    As I understand it, they were added into WP core not merely because this is an oft-requested feature, but also because theme and plugin authors can override the function in order to pull in avatars from sources other than Gravatar.

  33. Aidil Omar (1 comments.) says:

    Doesn’t work on my theme. :-(

  34. Monty Flinsch says:

    Thanks for the helpful info

  35. lostasylum (1 comments.) says:

    my avatars don’t work on my own website either… i tried using the option here: http://www.dezzain.com/wordpre.....tegration/ but all it did was mess up my comments portion…. any idea?

  36. Ruben Omar Cobos Leal (1 comments.) says:

    Excelent tuto , iwas looking exactlly for this :)

  37. John Crenshaw (1 comments.) says:

    Has anyone had any problems with the avatar-default class being assigned to the image if the default image is used. For some reason that class isn’t being assigned when the default avatar is used. I’m trying to hide the avatar if the default is used and have no way to differentiate the default images from the rest.

  38. NsaneNoob (1 comments.) says:

    Gravatars are a great adition to WordPress.

  39. Jeff (1 comments.) says:

    Thanks for the article.. I didn’t realize even though gravatar’s are built into wordpress that you still have to install the gravatar plugin. Got it working now.. thanks.

  40. don (1 comments.) says:

    Nice post. I have been searching for this exact info. Thanks!

  41. martijn says:

    Doesn’t seem to work…..

  42. a?k ?iirleri sevgi (1 comments.) says:

    Hi, how can i get 2.5 themes?

  43. Justin Kistner (1 comments.) says:

    I was getting the error “Unexpected character input”, but I was able to fix it using double quotes around the number value for size.

  44. Joe says:

    Ca we make our own gravatar image on wordpress.com?

  45. Michael (1 comments.) says:

    After a long overdue upgrade, the tips worked like a charm. Thanks!



Trackbacks/Pingbacks

  1. [...] printscreen tirado no wordpress 2.5 configurando o gravatar , bastante fácil não é? vejam mais detalhes aqui Estou bastante ansioso para ver todas as novidades desta nova versão mas já disse apenas usarei [...]

  2. [...] el motor gestor de contenidos que utiliza esta web. Una de las novedades que incluye es el soporte de avatares (por ejemplo los de Gravatar.com) directamente incluidos, sin necesidad de instalar ningún plugin. [...]

  3. [...] L’articolo integrale è in inglese, disponibile si weblogtoolscollection.com [...]

  4. [...] for gravatars. However, I don’t think this will be as affected as the previous plugin as WLTC’s Ronald Huereca points out that you can enable or disable the built-in gravatar support and just use the plugin. One thing [...]

  5. [...] çal??abilmesi için yine tema dosyas?na bir iki kod eklemeniz gerekli. Nas?l yap?laca??na burdan bakabilirsiniz. Ayr?ca hangi rate seçene?iyle belirlenmi? olan avatarlar?n gösterilmesine de [...]

  6. [...] Tools Collection has documented the get_avatar() function present in WordPress 2.5 so that I don’t have to. Big thanks. I can scrap the avatar post I [...]

  7. [...] this post Ronald Huereca demonstrates how Gravatars will be used with WordPress 2.5. If you are comfortable [...]

  8. [...] Ryan Boren makes it official, avatars using the Gravatar Plugin is now incorporated into WordPress. Weblog Tools Collection wrote up the information on the new get_avatar() function to help WordPress Theme developers update their Themes and those who want to write Plugins [...]

  9. [...] Ryan Boren makes it official, avatars using the Gravatar Plugin is now incorporated into WordPress. Weblog Tools Collection wrote up the information on the new get_avatar() function to help WordPress Theme developers update their Themes and those who want to write Plugins [...]

  10. [...] doubted that full Gravatar support would make it into WordPress eventually. Weblog Tools Collection shows what they look like, how they’re managed, and how theme designers can implement [...]

  11. [...] Now you can simply make a PHP function call to get the associated gravatar for a user. You can read more about the gravatar changes in 2.5 here. While I’m on the topic, one thing that’s always bothered me about using gravatars is [...]

  12. Easy Gravatars 1.2…

    Earlier today, I released Easy Gravatars version 1.2. The only change (besides confirming that works in WordPress 2.5, currently in beta, due out next week) is that when installed under WordPress 2.5 or newer, it will use the new core get_avatar() fu…

  13. [...] ab WordPress 2.5 (zur Zeit haben wir WP 2.3.3., WP 2.4 wird bekanntlich übersprungen). Bei Weblog Tools Collection steht ausführlich wie es geht. Es wird eine get_avatar()-Funktion geben, die [...]

  14. [...] Weblog Tools Collection » Blog Archive » Gravatars and WordPress 2.5 ???WordPress 2.5 ??????????? Gravatar ????????????????? [...]

  15. [...] ????????: ????? ????? ????? ?????? ???????? ?????. ?????? ?????? ????? ??????? get_avatar ??? ?????? ?????? ???? ?? ????? ??????? ??????. ??? ?? ????? ???? ????? ????? ?? Weblog Tools Collections. [...]

  16. [...] qui vous permettra de faire apparaître les gravatar de vos lecteurs sans avoir besoin de plugins. Cet excellent article de Weblogtoolscollection vous permettra de mieux comprendre va fonctionner tout ça et comment l’intégrer à votre [...]

  17. [...] Gravatars and WordPress 2.5 [...]

  18. [...] Weblog Tools Collection » Blog Archive » Gravatars and WordPress 2.5 [...]

  19. [...] o gravatar incluído por padrão, sem a necessidade de plugins e/ou códigos estranhos, apenas com uma template tag simples. Essa novidade é reflexo direto da aquisição do gravatar pela Automattic, empresa por trás do [...]

  20. [...] çal??abilmesi için yine tema dosyas?na bir iki kod eklemeniz gerekli. Nas?l yap?laca??na burdan bakabilirsiniz. Ayr?ca hangi rate seçene?iyle belirlenmi? olan avatarlar?n gösterilmesine de [...]

  21. [...] ????????: ????? ????? ????? ?????? ???????? ?????. ?????? ?????? ????? ??????? get_avatar ??? ?????? ?????? ???? ?? ????? ??????? ??????. ??? ?? ????? ???? ????? ????? ?? Weblog Tools Collections. [...]

  22. [...] added note: According to Web Tools Collection, avatars will be included (preloaded) in WordPress version 2.5 (which is currently being [...]

  23. [...] ????????????,???????php???0?????????????WordPress 2.5 and Gravatar?????????? [...]

  24. [...] ?????gravatar???(??????<?php comment_text() ?>??)???????<?php echo get_avatar( $comment, 32 ); ?>?32????????????????????????????comments.php????????????? ???php??????????theme???????<?php echo get_avatar( get_comment_author_email(), ’32′ ); ?>????????……(??)? [...]

  25. [...] bueno eso nos vino bien a la comunidad WordPressera ya que ahora los gravatares son simplemente una función más de WordPress, no hay necesitad de usar plugins externos ni nada por el estilo, dicha función ya ha [...]

  26. Gravatare und WordPress 2.5…

    Wenn das mal gut geht – so könnte der Untertitel dieses Beitrags lauten. Denn mit der kommenden WordPress Version 2.5, die eigentlich schon für den 10. März angesetzt war, haben die Gravatare eine Dauerkarte im WordPress-Heimspiel bekomm…

  27. [...] ?????weblogtoolscollection [...]

  28. [...] echo get_avatar( get_comment_author_email(), ’32′ ); ?>???????……(??)? [...]

  29. [...] çal??abilmesi için yine tema dosyas?na bir iki kod eklemeniz gerekli. Nas?l yap?laca??na burdan bakabilirsiniz. Ayr?ca hangi rate seçene?iyle belirlenmi? olan avatarlar?n gösterilmesine de [...]

  30. [...] neaizg?ja pa ****, t?p?c biju mazliet kreat?vs un pievienoju koment?riem (yeah, ja t?di b?s) ieb?v?to Gravatar funkciju, lai jau ciemi?iem ar [...]

  31. [...] a really nice feature. Gravatar support is also built in so no need for separate plugins although some changes to themes are required to support [...]

  32. [...] comment ?????????????????????? weblogtoolscollection ???????????????????????? Gravatar ???? [...]

  33. [...] ??,???????,????Gravatars and WordPress 2.5 [...]

  34. [...] ??????? gravatar – ?????? ? ??? ???? ?????????? ??????? get_avatar() Tags: WordPress | March 30th, 2008 | 3 [...]

  35. Angi's Blog says:

    Endlich! WordPress 2.5 ist da…

    Nach langem gespanntem Warten ist nun endlich WordPress 2.5 veröffentlicht worden. Viele neue Features, unter anderem unterstützt es nun ohne Plugins Gravatare. Das habe ich natürlich gleich auf meinem Testblog ausprobiert, und es funkti…

  36. [...] [1 abril]: También se puede agregar Gravatar a los comentarios, que ya viene por defecto en WP 2.5. Basta incluir la función “echo get_avatar” en comments.php, yo la estoy probando con [...]

  37. [...] Squee! They’re working now! The clue I needed was in a post at Weblog Tools Collection. Now I can try updating the other [...]

  38. [...] in my comments admin page. WordPress had supported gravatars via plugins but now it looked like the code recognized them without intervention. Existing themes need to be tweaked to use gravatars natively so I just spent the last half hour or [...]

  39. [...] both weblogtoolscollection.com and boren.nu shows, one of the new features in WordPress 2.5 is to have default avatar support in [...]

  40. [...] ??,???????,????Gravatars and WordPress 2.5 [...]

  41. [...] Esto no lo he adivinado ni he obtenido la sabiduría por ciencia infusa ni nada parecido, lo he leído aquí. [...]

  42. [...] bem certinho p/ eu aprender adicionar o meu avatar. Foi futucando mais uma vez que encontrei o http://weblogtoolscollection.com esse tinha o que eu procurava. Bom, para vc adicionar um avatar p/ seu blog wordpress, primeiro [...]

  43. [...] first place I saw to provide a function rather than a variable is the weblog tools collection post on gravatars. The above is their recommendation with size 32 image. I picked this size because it is the size of [...]

  44. [...] You might browse through the Gravatar (aka Avatar) feature added at WordPress on Web Tools Collection here. [...]

  45. [...] Gravatars and WordPress 2.5 [...]

  46. [...] Gravatars and WordPress 2.5- Several commenters mentioned on yesterday’s post regarding Gravatars without a plugin that WordPress 2.5 would be having built-in Gravatar support. And indeed WordPress 2.5 will come with Gravatar (aka, Avatar) support. … [...]

  47. [...] Gravatars and WordPress 2.5 – Several commenters mentioned on yesterday’s post regarding Gravatars without a plugin that WordPress 2.5 would be having built-in Gravatar support. And indeed WordPress 2.5 will come with Gravatar (aka, Avatar) support. … [...]

Obviously Powered by WordPress. © 2003-2013

page counter
css.php