Age of Article Warning:
This article was originally published 47 months ago. The tips and techniques explained may be outdated, or information may longer be applicable. Please consider this when viewing the below content.

Today’s tutorial is a simple trick to

changing the default gravatar in WordPress that shows up next to the comments.

Why do this, you might ask? Well there are 2 reasons, one of which you may not be aware of, and actually is surprisingly important.

But firstly lets make sure everyone knows what a gravatar is- the grey mystery man, the blue box with what looks like a power button inside it- that is a gravatar or a globally recognised avatar. These are the default images that load when a viewer leaves a comment on a blog.

If you see a custom image of the person, or a logo or another image, then this is because they have set up a Gravatar account. See here for more info on this.

So the first reason for changing the default is that default gravatars are pretty ugly up there on a blog in the comments. Wouldn’t it be much nicer to make your own customised image that ties in with your theme?

The second reason, and this is important, is that every time a gravatar image is displayed on your page it is sending out a new HTTP request to get that image. So if you have lots of comments, then that could be extra loading time accessing the gravatars from the gravatar site. It would be far better to have your own local image loading.

So how do we do it? Well it’s really simple.

Step 1: create a very small size image file. I used an image of 48px by 48px and saved it with a filesize of 2.76kb

Step 2: upload this image into your childtheme’s images folder (create one if it doesn’t already exist)

Step 3: add the code snippet below to your childtheme’s functions.php file. Replace NAME with the name of your Gravatar for displaying in the discussion settings in your wordpress admin and IMAGENAME.png with your filename.

[php]
add_filter( ‘avatar_defaults’, ‘newgravatar’ );
function newgravatar ($avatar_defaults) {
$myavatar = get_bloginfo(‘stylesheet_directory’) . ‘/images/IMAGENAME.png’;
$avatar_defaults[$myavatar] = "NAME";
return $avatar_defaults;
}
[/php]

Change the Default Gravatar in WordPress was last modified: February 12th, 2013 by David Tiong
Change the Default Gravatar in WordPress