Replacing plugins with template code: Gravatars
Lately I've been trying to reduce the number of plugins I've got loading to speed up my WordPress a bit, especially those plugins that do "stuff" in my theme. I've been replacing these plugins with template code, and this is the easiest fix I had so far: I replaced a 40k gravatar plugin with one (!!) line of code which generates all the images:
<img class="gravatar" alt="gravatar" src="http://www.gravatar.com/avatar.php?gravatar_id=<?php echo md5($comment-/>comment_author_email); ?>&rating=R&size=80&default=http%3A%2F%2Fyoast.com%2Fimages%2Fgravatar.png"/>
The source URL there needs some explanation:
- the gravatar id is an MD5 hash comment author's email address
- the rating can be G | PG | R | X
- the default is the URL to my default image, instead of the blue gravatar image
Now my gravatars plugin did some server-side caching, but since Automattic acquired Gravatar a while back, they're now super fast, and all that caching can just slow your site down, because you can't beat their performance anyway.





by Adam Dempsey on 13 March, 2008 at 10:11
That's great! I'm going to switch that over on my sites now :) Thanks
by DazzlinDonna on 13 March, 2008 at 14:20
Will this change next week when WP 2.5 is released? I thought they built gravatars into the new release, but I haven't paid a lot of attention to the details.
by Joost de Valk on 13 March, 2008 at 15:01
@Dazzlindonna yes they did, but that will probably do something similar to this :)
by seosurvivor on 13 March, 2008 at 17:23
Did you just do that overnight? For some reason my gravatar wasn't showing on your comments yesterday, but it's showing today. weird...
Anyway, thanks for another useful tip!
by Scott Johnson on 13 March, 2008 at 21:44
Nice hack! I'm going to try to do something like this right away on my current theme.
by Henri on 13 March, 2008 at 21:53
Joost, you can also use for <?php echo the shorter version: comment_author_email
Are your sure? Ik think it must be
$comment->comment_author_email
by Henri on 13 March, 2008 at 21:55
Hmm, the short tag was replaced.
This one: < ? = (without spaces)
by Joost de Valk on 13 March, 2008 at 21:56
@Henri it says $comment->comment_author_email ;)
by Domain Registrar on 13 March, 2008 at 21:59
Very interesting article! Keep up the good work.
by Jermayn Parker on 14 March, 2008 at 01:59
Love it?
With WP 2.5 correct me if im wrong but does this mean we wont need the Gravatar Plugin anymore??
by Drew Stauffer on 14 March, 2008 at 19:01
its all about the speed.
Great stuff Joost
by Roelof on 27 March, 2008 at 15:47
Nice one Joost! Still i'm just gonna wait for the WP 2.5 ;)!
by Alex on 31 March, 2008 at 13:29
It's not so usefull change.
You've replaced local gravatar reference (possibly cached by plugin like Gravatars2) with remote call to gravatar.com site. Thus, your site now is fully dependable on gravatar.com, which sucks very often. I'd never make such a change. Vice versa, I am trying to use local cache where is possible.
IMHO.