Show custom default avatar instead of gravatar

I'm using this custom function to get the default avatar from my server instead of gravatar:

if(!function_exists('custom_avatar')){
    function custom_avatar($avatar_defaults){
        $new_default_icon = 'http://localhost/gv/wp-content/images/mystery-man.png';
        $avatar_defaults[$new_default_icon] = 'Custom Avatar';
        return $avatar_defaults;
    }
    add_filter('avatar_defaults','custom_avatar');
}

but the custom avatar is not showing up, when I view source code then the src of the image look like this:

http://0.gravatar.com/avatar/a432e8915b383edd8d25c2a4fd5a6995?s=32d=http%3A%2F%2Flocalhost%2Fgv%2Fwp-content%2Fimages%2Fmystery-man.png%3Fs%3D32r=Gforcedefault=1

Why does my image src relative to gravatar here? How can I fix this problem?

Topic gravatar avatar functions php Wordpress

Category Web


just use the function get_avatar, $default is for your custom default.

<?php echo get_avatar( $id_or_email, $size, $default, $alt, $args ); ?> 

https://codex.wordpress.org/Function_Reference/get_avatar

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.