Gravatar stands for “Globally Recognized Avatar”, which is a service from Automattic. You can signup on their website and upload an avatar which is then linked to your email and whenever you use the same email address, that custom avatar will be shown. But when a user comments on your site and they have not signed up for Gravatar, then a default Gravatar is shown, which you can select from the Discussion settings of your WordPress Dashboard.

default avatar

Most websites use the default ‘Mystery Man’ avatar, but on many websites, you may have noticed that they use custom Gravatar. So instead of the default pre-defined avatars, you can set your own custom avatar image. Let’s take a closer look at how this can be achieved.

Open your theme’s functions.php file and paste the following code:

add_filter( 'avatar_defaults', 'new_default_avatar' );

function new_default_avatar ( $avatar_defaults ) {
		$new_avatar_url = get_bloginfo( 'template_directory' ) . '/images/new_avatar_image.png';
		$avatar_defaults[$new_avatar_url] = 'avatar_name_here';
		return $avatar_defaults;
}

Now, there are two options that you need to change. The first is the path of the avatar image file, which points to the images folder in your theme, and then change the name of the image also.

/images/new_avatar_image.png

The second option that you need to change is the name of the avatar that will appear in the WordPress discussions page. Change this name to what best describes your custom avatar:

avatar_name_here

There’s one last thing remaining that you need to perform. Go to the Discussion settings page and now you will see the newly uploaded avatar, with its name as you have defined. Choose this new avatar and hit the Save button.

That’s all you need to do. Now visit the front-end of your website and check those comments that have not associated any Gravatar with it. Those Gravatars will now be displaying your newly uploaded custom avatar. This method is also used for better branding of your website. Go ahead, try it out.

Leave a Reply

Your email address will not be published. Required fields are marked *