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

    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;

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


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

  • Possible duplicate http://wordpress.stackexchange.com/questions/159482
    – Robert hue
    Sep 26, 2014 at 8:56
  • Whereever you want display your custom avatar, do something like this in that template of your active them: <div id="author-avatar"> <?php _e('<img src="'.get_bloginfo('stylesheet_directory').'/images/admin-avatar.jpg" width="48" height="48" alt="' . get_the_author() . '" />');?> </div><!-- #author-avatar -->
    – Tara
    Sep 26, 2014 at 15:53

2 Answers 2


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

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



Just add this in your functions.php file (Image URL must be complete). Then go to the gravatar choice section and choose the new avatar.

/*** Change default gravatar */
add_filter( 'avatar_defaults', 'new_gravatar' );
function new_gravatar ($avatar_defaults) {
$myavatar = 'https://example.com/image.webp';
$avatar_defaults[$myavatar] = "Default Gravatar";
return $avatar_defaults;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.