Implementation of Gravatar is an uprising trend that is being seen on many WordPress Blogs. More and more blogs are following the trend by incorporating the gravatar. Not only bloggers, but theme designers are also focusing on making the best comment box for their WordPress themes and implementing gravatar with creativity.
While bloggers may know about gravatar and have an account, there are other users who don’t have a personal gravatar, so when they post a comment on a blog, a mystery man takes over their gravatar. You probably have seen it on many blogs, on a gray background a white guy. In this article we share a way to have a custom gravatar for your blog users which you can incorporate in your blog.
![]()
As you can see in our comment box, when a user who does not have a gravatar account comments, our wpbeginner logo shows up. You can do the same now. First thing you need to make sure is that your theme have gravatar enabled.
1. Open your functions.php file which is located in your themes folder.
2. Then paste the following code in there
add_filter( 'avatar_defaults', 'newgravatar' );
function newgravatar ($avatar_defaults) {
$myavatar = get_bloginfo('template_directory') . '/images/gravataricon.gif';
$avatar_defaults[$myavatar] = "WPBeginner";
return $avatar_defaults;
}
You need to understand the variables in the code above.
‘/images/gravataricon.gif’ is the location of the image file. It must be saved under the theme folder that you are using.
Change WPBeginner to the name that you want to give your Gravatar and you should be all set.
3. Upload this file
4. Login to your WordPress Admin Panel and click on Settings > Discussion
![]()
Your gravatar now show up like the picture above displays. Select it and save changes, and you are all set.
Now you should be able to change your gravatar in no time.







What if you’re using a child theme …
I changed the line
$myavatar = get_bloginfo(‘template_directory’) . ‘/images/gravataricon.gif’;
to
$myavatar = get_bloginfo(‘stylesheet_directory’) . ‘/images/gravataricon.gif’;
but still not working
Is the image not showing or the code altogether is not working (i.e it’s not even adding an option for custom gravatar)?
I just used your advice here; more explanation that the image needed to be saved in the themes folder too would have been helpful. But your tips here helped me figure some of it out. Thanks.
@wpbeginner Secondly , do you know an good pre image loading plugin for wordpress
@wpbeginner disquess is having some problems at my blog see there http://freakify.com it is not allowing me to upload any custom image>>>? Why
@mrahmadawais That is because Disqus is a third party platform….
tell me plz
any one here now to tell me why disquss is not accpting this
thanx it worked perfectly!
This gravatar custom code is very cool and really work on my blog. Thank you very much.
You rock WPbeginner.
This gravatar custom code is very cool and really work on my blog. Thank you very much.
You rock WPbeginner.
@Kindar We are glad to have you as a user
Let us know if you have any suggestions.
When ever I search for something on the internet i usually get to see your website.. Now I started follow your website and the stuff you share.. What ever you share its really useful and thats why i always check it up, and see whats new. Also i wanted to thank you for the last subject.
When ever I search for something on the internet i usually get to see your website.. Now I started follow your website and the stuff you share.. What ever you share its really useful and thats why i always check it up, and see whats new. Also i wanted to thank you for the last subject.
where is located the file /images/gravataricon.gif ?
Inside your WordPress Theme’s folder.
Hi!
Wow..I’ve gone round and round with code. Not adept with this as a newb…but usually can get things to work.
I added the code to get a default avatar for guest . It worked. At least in admin. The image shows up in ADMIN..but not on the website.
I also signed up at gravatar for my own custom gravatar for my ADMIN comments…and it shows up in their “check point”…but cannot get it to show up in my comments.
Neither does the Guest Gravatar.. but the GRAVATAR image shows up instead.
My custom image IS checked as default in Discussions. Both images are uploaded to the theme/images and the path to the guest image is correct in the code. I made the images 128 x 128 as suggested online nowadaZe… Dunno if THAT sizing must be specified somewhere? I looked thru the functions code…as best as my bewildered eyes can comprehend..but didn’t finding anything that looked like it would work. Maybe in style.css?… Dunno if it makes a difference. Don’t want to go thru changing everything..and still not work. Have already spent DAYS trying to figure this out. Should be a simple thing.
Don’t understand why MY admin gravatar isn’t showing. Per what I read…it should be handled via gravatar. The email address used for the gravatar is the same as listed in admin.
WHAT am I doing wrong/missing?.. I have WP 2.8.4.
I tried pasting the above code at the top…AND at the bottom… but neither works. Does it matter WHERE you paste it in the functions.php?
Can you suggest anything?Would DEEPLY appreciate any help you can give. Can give you any code you might need…just specifiy.
Thank you in advance. tearing out hair..
It sounds like that this issue is not with the function rather it is the comments.php file error.
thanks for this tip. I used this on my site and the default avatar is showing up in the comments section but not in the “Recent Comments” side bar. I’m using the “Get Recent Comments” plugin. Is this treated differently?
http://interactiveblend.com/blog
Unless that plugin has specified a default in their code, this should work. It means the plugin is not coded properly. Contact the developer, and ask them to fix it.
The code works if placed in custom-php.php which has the advantage of sticking through upgrades.
Do you have any ideas on the code for removing the html calls to gravitar.com in buddypress?
Thanks for the tip. Works flawlessly.
I noticed wordpress is changing the quote into a backquote, you should use
'instead of’Problem fixed.
This is the code snippet I was looking for.
But it doesn’t work properly… I put in the code into my functions.php (I’m sure everything is correct, also the path to my picture).
But when I go to discussion, I can’t see my Avatar, and also the WP-backend is a little bit broken… The code i put into the functions.php shows up above the header of the WP-backend.
Can you help me please? Maybe I didn’t only a little thing wrong??
The code above is 100% correct because that is what we are using. I don’t know what you can potentially be doing wrong. But without looking at your codes we won’t be able to help you out. You can hire us for a small fee, and our staff can surely fix the problem.
I think I may be having the same trouble as fantasmo. The snippet works and the gravatar shows up within the discussion admin page but when you click on ‘save changes’ to save the options, you get a white screen which displays the footer from the option-discussions.php instead of the full page saying that the options have been saved.
I saw the same results as Fantasmo. When I copy/pasted the code, the blank line between the add_filter and the function was lost for some reason. Putting the blank line back seemed to fix the problem.