Change the default gravatar image in wordpress

All of us may have noticed that worpress automatically assigns a default image to those posts or comments that don’t have a customized gravatar attached to it, Usually the automatically assigned image is a gray silhouette that may no fit the look of your well designed website. Have you ever wondered if this silhouette can be changed for a better image or even a customized one?

Well wordpress provides the possibility of choosing one of the six gravatars that are installed by default with your wordpress theme. You can choose one of the available gravatars by logging to your wordpress admin panel then on the left side of your pannel go to Settings then click on Discussion Now you should see the gravatar options you may want to select one of them and then Save changes to activate it.

So far good, but what if you don’t like none of those options that already ship with wordpress. Well, It is quite easy to add a customized gravatar to the existing list. The trick is to add a small chunk of code to the “functions.php” page that you may find in your active theme folder. In case this page dosen’t exist go ahead and create one and name it “functions.php”. Now here is the code we need to place in that page.

if ( !function_exists('fb_addgravatar') ) {
function fb_addgravatar( $avatar_defaults ) {
$myavatar = get_bloginfo('template_directory') . '/images/gravatar.png';
$avatar_defaults[$myavatar] = 'No Gravatar';

return $avatar_defaults;
}

add_filter( 'avatar_defaults', 'fb_addgravatar' );
} 

Basically what all this code does is to make available another option in the list of default gravatar. In order for this to work you have to make sure that a correct path to the new gravatar image is assigned to the variable “$myavata”. It is possible to host your new gravatar image in your sever and point to it using an absolute path or you may just want to use one of your gravatars in the gravatars website and point to it from your “functions.php” page.

In the following image you can see how does the gravatar list look before and after adding a customized gravatar.
gravatar-list

I hope you find this tutorial useful and I encourage you to leave your comments and opinions in the form below. And if you think there is a better way to do it please let  us know.

Tags: , , , , ,

Follow the responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.

Leave a Reply




XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>