Support » Fixing WordPress » Add a customized default avatar… php function won't work

  • Hi, I’ve looked online and found a way to add a default avatar into wordpress. I’ve followed what was described and have been trying for a while now, but nothing seems to work, so I’m asking for a little help.

    For info, I’m using the catch-box theme.
    So here’s what I did :

    1) created a 90×90 pixels jpg file
    2) saved the image in ‘wp-content/themes/catch-box/images’
    3) opened functions.php (in catch-box folder)
    4) pasted the code I found, somewhere in the file :

    add_filter( ‘avatar_defaults’, ‘newgravatar’ );

    function newgravatar ($avatar_defaults) {
    $myavatar = get_bloginfo(‘template_directory’) . ‘/images/my_image.jpg’;
    $avatar_defaults[$myavatar] = “My Image”;
    return $avatar_defaults;

    — it is now half-working. Meaning I see the name for my new avatar, but in the Settings, I see a blue square with a question mark, instead of my image!

    So, my questions are:

    1) Is the code correct? What else could I try?
    2) Where exactly in functions.php should the lines of code be saved?
    (without messing things up ; ))
    3) If I repeat the code, could I technically add a 2nd new default avatar?

    4) My blank avatar in Settings is now showing a “question mark” in a blue square (?) as well / It used to show a “white square”.
    Why is that? And could it be linked to my problem?

    THANK YOU very very much for your help..
    I’m usually very motivated to find things on my own.. and I eventually succeed ! But this time, I’m stuck.


    Note: I can’t share my url yet, as I am working locally using MAMP.

Viewing 8 replies - 1 through 8 (of 8 total)
  • dogriad38370


    Hi stephanie, I do have the same issue ! My image is not showing, just the new option with the name of the avatar !

    Is there anyone who could help us please ?

    WordPress : 3.4.2
    Theme : Twenty Eleven



    Hi again..
    I thought about something.. and it might help someone for an answer.

    I still have no clue why I can’t see the images for those 2 avatars. So I’ve copied the “image addresses”.. so here it is :

    My site is in local at the moment.. and this might be part of the problem.
    (even if it should work anyway)

    Address for the BLANK AVATAR (not showing) :

    Address for the Customized AVATAR (which I added / not showing) :

    If I compare this to another image in the site, for ex. the logo in the header, I have this :

    —-> it’s not the same route. Probably not using the same “code” to get to the images”. And I’m sure that’s why I get a “question mark” instead of an image.

    Can someone help me out?
    I’d highly appreciate it.

    Thank you,

    I do believe that the jetpack plugin is interfering

    You have your images being cached by jetpack, but it doesn’t pick up the header image, so your header is being served fine, but the rest of them have the screwy path



    I don’t have a jetpack plugin installed… not that I see…

    What is it for ?
    Is it installed by default maybe?

    You don’t?

    Hmmm… Jetpack recently added a feature called Photon, which allows you to serve images from their servers…

    the URLs you posted are formed like the photon URLs, but I guess I’m barking up the worng tree, apologies!



    Too bad….
    I wish it could have been that. I’m so lost here.

    But thank you anyway!



    Gravatar needs to be able to see that file actually exists.

    I had a problem with testing on a local site and then uploading and changing my hosts file. I could see the image there but could not. Make sure you upload your default gravatar to somewhere its API can see.

    More info here:

    Hi guys,

    i’ve tried to use the urlencode() function but is still changing my src into this

    I have saw some tutorial about a plugin that will help me to change the default avatar, but I would like to understand how is possible that is not working with this code.

    I am running 3.4.2 version with a custom theme and JetPack installed, but I do not use Photon…

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Add a customized default avatar… php function won't work’ is closed to new replies.