How to Change the Default Gravatar On WordPress using custom code?

Hello friends!!

In wordpress when user give the comment and write post then automatically display default Gravatar image.
You can see below my screenshot Mystery Person option is default selected and you can select below default options.

Now you want to add  your custom gravatar image using custom code then follow below steps.

Step1 – First add your Gravatar images in media library.

Step2 – Then below code add in your function.php file. Don’t forgot replace $myavatar value with your Image URL.

add_filter ('avatar_defaults', 'wpb_new_gravatar');
function wpb_new_gravatar ($avatar_defaults){
$myavatar='http://example.com/demo/toursite/wp-content/uploads/2019/12/gravtar.png';
$avatar_defaults[$myavatar] = "Customize Gravatar";
return $avatar_defaults;
}

Step3 – Go to Settings » Discussion you can see your Customize Gravatar added to default avatar choices. Then click on the save changes button. Please refer my below screenshot.

Now you can see your customize Gravatar image like below my screen shot.

I hope this article helpful for you.

Thank you 🙂

Blog Catagory : WORDPRESS