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.
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
Thanks for an update. Seems you already fixed it 🙂
Not 100% if it was that or if I accidently deleted index from the server block. All the same fixed now.
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! 🙂
Hi there – For all existing comments, you may not be able to change author URL. You could do it by changing URLs to DB directly.
thanks for all your help! much appreciated 🙂
I can’t get this work on my child theme. Any advice please?
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.
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”
hmm. Great Nathan.
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
I have been searching the internet everywhere and this comment saved me. Thank you. 😀
awesome. glad it worked for you.
Excellent!
But if you use child theme, change (‘template_directory’) to (‘stylesheet_directory’)
Thanks Komarik for suggestion.