How to Change Default Avatar / Gravatar in WordPress

Last updated
App Shah

Crunchify » WordPress Optimization and Tutorials » How to Change Default Avatar / Gravatar in WordPress

As you all know, WordPress blog is among the best blogging platform. WordPress has a default gravatar for people on my blog that do not have their own gravatar.

Just in case if you want to change default Gravatar on your blog then simply follow below steps.

Step-1.

Open your theme’s functions.php  file.

Step-2.

Add below code at the end of file.

add_filter( 'avatar_defaults', 'crunchifygravatar' );

function crunchifygravatar ($avatar_defaults) {
    $myavatar = get_bloginfo('template_directory') . '/images/avatar.png';
    // OR --> $myavatar = "https://crunchify.com/Crunchify.png";
    $avatar_defaults[$myavatar] = "Crunchify Avatar";
    return $avatar_defaults;
}

Step-3.

Head over to Settings -> Discussion -> Default Avatar  Section.

Step-4.

Select your new avatar and click Save Changes.

Choose your custom Gravatar in WordPress - Crunchify Tips

15 thoughts on “How to Change Default Avatar / Gravatar in WordPress”

  1. Looks like this dosn’t work anymore for some reason? Any ideas?

    I used the exact same code above and added the avatar.png to theme images folder. When I use Chromes Dev tools the image src= the below. For some reason the http://0.gravatar. com site is still being pulled in before.

    src=”http: //0.gravatar. com/avatar/3cd797eb8894e1f826d51deab7d2e176?s=32&d=http%3A%2F%2Fstaq%3A8887%2Fwp-content%2Fthemes%2Fshopkeeper%2Fimages%2Favatar.png&r=pg&forcedefault=1″

    Sorry think I figured it out as Im using a local setup currently

    Reply
  2. Is it possible to change the link on my current avatar from wordpress to a self hosted site? I changed my primary site on the settings but it still pulls up my wordpress link.

    TIA! 🙂

    Reply
    • Hi Sam. avatar_defaults is a default WordPress hook and should work by default. Which theme are you using? Would suggest to check this on default WordPress theme TwentyFifteen.

      Reply
  3. I end up with a path to Gravatar preceeding the URL, like: src=”http:// gravatar. com/avatar/28d3b36956f2493a71a5bb61df1974f7?d=http://localhost:8888/wp-content/themes/mytheme/img/default-avatar.png&s=75&r=G”

    Reply
    • It will not work with localhost: In fact, what happens is that gravatar’s server will request your image url, and will probably check it can be accessed (or even maybe get it to send it back, I do not know)…
      But, for sure, gravatar’s will not access your localhost.
      Online, altough, it will work for sure

      Reply

Leave a Comment