Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

How to Change the Default Gravatar on WordPress

Last updated on by
Elegant Themes
How to Change the Default Gravatar on WordPress

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.

Good Bye Mystery Man

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

Gravatar Settings

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.


Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »

Comments

  1. Karan Rawat says:

    It works. Thanks Bookmarked your blog!

  2. Chuks Emmanuel says:

    Thank you Syed Balkhi. it really worked for me. just keep the good work going.

  3. Adrian O'Farrell says:

    Hi, just checking what happens next

  4. Simen Eggen says:

    Thank you so much :) it’s working :D

  5. Sadia says:

    Thank you so much for these instructions. For some reason, things were wonky when I used a .png file, but a gif worked easy peasy!

  6. Katelyn says:

    I am having the same issue as Keely. I am using a child theme so get_bloginfo does not work. When I check the URL of the broken image it displays the path to the parent theme. Is there a way to get this to work with a child theme?

  7. Akash KB says:

    What should be the size of the image file to be uploaded to the theme folder?

    Thanks :)

  8. Brody says:

    Any way to make this use a SSL connection using the same code? Always loads “insecure content”. What changes to make it a secure image during loading?

    • WPBeginner Support says:

      If you are loading gravatar on a secure page then it should automatically load securely. Also check Settings » General change your site and WordPress address to use https. Let us know if this solved the issue.

  9. Pavan Deshpande says:

    Thank you for sharing this , i was not able to change the default image but after reading this i changed

  10. Keely says:

    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 :(

    • Editorial Staff says:

      Is the image not showing or the code altogether is not working (i.e it’s not even adding an option for custom gravatar)?

      • Kristen says:

        I am having issues with the code also. I used it on another site and it worked perfectly, however on the site I’m currently working on… it shows as an option in the admin panel under settings-discussion, however it is showing as a broken image and does not display on the blog pages either. Any help is greatly appreciated.

        • Editorial Staff says:

          Right click on the broken image to get the image URL. Open that URL in another tab to verify that the URL is correct.

  11. Rachel says:

    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.

  12. mrahmadawais says:

    @wpbeginner Secondly , do you know an good pre image loading plugin for wordpress

  13. mrahmadawais says:

    @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

  14. wpbeginner says:

    @mrahmadawais That is because Disqus is a third party platform….

  15. mrahmadawais says:

    tell me plz

  16. mrahmadawais says:

    any one here now to tell me why disquss is not accpting this

  17. Crysislevel says:

    thanx it worked perfectly! :)

  18. Shabil Team says:

    This gravatar custom code is very cool and really work on my blog. Thank you very much.

    You rock WPbeginner.

  19. Shabil Team says:

    This gravatar custom code is very cool and really work on my blog. Thank you very much.

    You rock WPbeginner.

  20. wpbeginner says:

    @Kindar We are glad to have you as a user :) Let us know if you have any suggestions.

  21. Kindar says:

    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.

  22. Kindar says:

    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.

  23. iur says:

    where is located the file /images/gravataricon.gif ?

  24. Cee says:

    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..

    • Editorial Staff says:

      It sounds like that this issue is not with the function rather it is the comments.php file error.

  25. Louis Gubitosi says:

    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

    • Editorial Staff says:

      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.

  26. martin says:

    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?

  27. JD says:

    Thanks for the tip. Works flawlessly.

  28. Desik says:

    I noticed wordpress is changing the quote into a backquote, you should use ' instead of

  29. fantasmo says:

    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??

    • Editorial Staff says:

      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.

      • Tracy says:

        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.

    • CC Rogers says:

      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.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.