Replace default avatar

I’ve searched google quite a bit and every site has the same filter but it doesn’t seem to be working for me. Not sure if it’s my setup or just old code.

I’m trying this:

Read More
add_filter( 'avatar_defaults', 'newgravatar' );  

function newgravatar ($avatar_defaults) {
    $myavatar = get_bloginfo('template_directory') . '/img/blog_noPhoto.jpg';
    $avatar_defaults[$myavatar] = "Default Avatar";
    return $avatar_defaults;
}

However, when I look at my template code it’s adding http://0.gravatar.com/avatar/?d= before the full URL of the image. I am using the “User Avatar” plugin but it seemed to be the same if I disabled that.

Related posts

Leave a Reply

2 comments

  1. I figured this out. The server I am working on doesn’t have access to the outside. So, even though the image is in my template folder, the gravatar.com call in front of the image path was causing the error.

  2. It is giving you that error because the image doesn’t exist. I would try changing it to:

    add_filter( 'avatar_defaults', 'newgravatar' );  
    
    function newgravatar ($avatar_defaults) {
        $myavatar = site_url() . '/img/blog_noPhoto.jpg';
        $avatar_defaults[$myavatar] = "Default Avatar";
        return $avatar_defaults;
    }
    

    So the link to the image file would actually be, http://www.example.com/img/blog_noPhoto.jpg