Do you want to change the default Gravatar on your WordPress website? Adding your own default gravatar image can make your comments section branded and attractive.
Gravatar is an uprising trend that is being used on many WordPress Blogs. Not only bloggers, but theme designers are also focusing on making the best comment box for their WordPress themes and implementing gravatar with creativity.
We talked about what Gravatar is and why you should use it in our previous post. And today, we are going to show you how to change the default gravatar on WordPress.
What is Default Gravatar and Why Change it?
Gravatar is a web service created and run by WordPress co-founder Matt Mullenweg’s company called Automattic. It is nothing but the image associated with your email id. The avatar image is then displayed on all WordPress blogs where users leave comments or write blog posts.
Every WordPress website comes with built-in support for gravatars and automatically shows users’ avatars when they write posts or leave comments.
If a user doesn’t have a gravatar image, then WordPress automatically shows the default gravatar image. The default option is to show an image called “mystery man”. But, you can change it to your own branded image.
Here’s how you can do that.
How to Change the Default Gravatar on WordPress
You will first need to visit the Settings>Discussion page on your dashboard and scroll down to the Avatars section. This is where you can simply change gravatar settings on your WordPress website.
Now you’ll see few choices available under the default avatar option. These avatars are used when a user doesn’t have a gravatar account associated with their email address.
WordPress uses the mystery man icon as the default gravatar if someone doesn’t have a gravatar ID. You can change that to blank or the gravatar logo.
You will also see some other options that are automatically generated images in different designs. These images use the author’s name or email address to mathematically generate a unique gravatar image.
Click on the Save button after changing your default gravatar.
Using Custom Default Gravatar Image in WordPress
You can also use your own default gravatar images as well. First of all, you need to create an image that you want to use as your default gravatar. The image should be 250×250 pixels.
Now, you will have to upload the image to your WordPress website first. For that, you can go to Media> Add New and upload your custom default gravatar image.
After your image is uploaded, click on the Edit Link next to the image.
WordPress will open your image for editing now. Copy the image file URL and paste it in a plain text editor like Notepad or Word.
Now it’s time to add some code to your WordPress site. Add the following code to your theme’s functions.php file or a site-specific plugin.
add_filter( 'avatar defaults', 'wpb_new_gravatar' ); function wpb_new_gravatar ($avatar_defaults) { $my_avatar = 'http://example.com/wp-content/uploads/2017/01/wpb-default-gravatar.png'; $avatar_defaults[$my_avatar] = "Default Gravatar"; return $avatar_defaults; }
Don’t forget to replace the $my_avatar value with the URL of the custom gravatar image you uploaded earlier.
Now go to Settings> Discussion page and you will be able to see your custom default avatar added to default avatar choices.
Select your custom default gravatar image and click on the save changes button.
WordPress will now use your image for users who don’t have their gravatar associated with their email addresses.
There you go, you can now successfully change the default Gravatar on WordPress without any difficulty.
If you have anything to add or feeling difficult to change the default Gravatar, please do let us know through the comments below.
Source: WP Beginner
Hello. Nice post! a quick note: the code has a few mistakes that make it not work. Here it is with the corrections:
add_filter( 'avatar defaults', 'wpb new gravatar' );
function wpb_new_gravatar ($avatar_defaults) {
$myavatar = 'http://example.com/wp-content/uploads/2017/01
/wpb-default-gravatar.png';
$avatar defaults[$myavatar] = "Default Gravatar";
return $avatar_defaults;
}
Hello DarkMG73,
Thank you so much for pointing out the error. We’ve updated the code in the article. Once again, Thank you for your kind words.
I get the error: Your PHP code changes were rolled back due to an error on line 51 of file wp-content/themes/circle-child1/functions.php. Please fix and try saving again.
syntax error, unexpected ‘defaults’ (T_STRING)