How to Change Default Gravatar in WordPress

Gravatar is one of the best features of the WordPress. It is nothing but the image associated to your email id. Whenever you use this email address for placing comments or create profiles in WP blog, the image associated to your email is displayed.

You can read more about Gravatar on WP because this tutorial is not about ‘what is gravater?’ So in this tutorial I am going to show you how to change the default “Mystery Man Gravatar” to your very own “Guest Gravatar”.

You can use gravatar in wordpress with the gravatar wordpress plugin or it can be manually added in index.php, comments.php and comments-popup.php

Many times the gravatar comes with the WordPress Theme, so in this case it is located in the functions.php file. This file is responsible for additional options of the theme which appears in the WordPress Dashboard.  So let’s add the new gravatar.

Open functions.php file. Add the following code at the end of the file just before and save it.

/* Powerusers Gravatar
/* ----------------------------------------------*/
add_filter( 'avatar_defaults', 'newgravatar' );  

function newgravatar ($avatar_defaults) {
     $myavatar = get_bloginfo('template_directory') . '/images/p-gravatar.jpg';
     $avatar_defaults[$myavatar] = "Powerusers Gravatar";
     return $avatar_defaults;
}

Explanation:

First line is adding a “newgravatar” to the default avatars (avatar_defaults) available in the WordPress.

add_filter( 'avatar_defaults', 'newgravatar' );
Default Avatar in WordPress
Default Avatar in WordPress

Next the newgravatar function is providing the location of the image which is in the images folder of the WP installation directory and assigning a name “Powerusers Gravatar” to it.

function newgravatar ($avatar_defaults) {
     $myavatar = get_bloginfo('template_directory') . '/images/p-gravatar.jpg';
     $avatar_defaults[$myavatar] = "Powerusers Gravatar";

And finally the output is sent back to default avatars (avatar_default) which displays the gravatar in the default gravatar list in the dashboard.

return $avatar_defaults;

Now go to your Dashboard->Setting->Discussion. Scroll down the page and select your new default gravatar. And you are done.

Here is the New Avatar!
Here is the New Avatar!

You can customize the size and look of the Gravatar for the comments section.

For changing the size, open functions.php again and look for the following code and change the size in $size=” ” field.

 get_avatar( $comment, $size='50' );

You can customize the look by editing the style properties for gravatar class in the style.css file.

So now on there will be no Mystery men in your blog.

What do you think about the Mystery Man? Do you want to keep the Default Gravatar or want your own? Let us know in the Comment!