WordPress.org

Ready to get started?Download WordPress

Forums

Add a customized default avatar... php function won't work (9 posts)

  1. istef8
    Member
    Posted 1 year ago #

    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 90x90 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.

    Cheers,
    Stephanie

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

  2. dogriad38370
    Member
    Posted 1 year ago #

    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

  3. istef8
    Member
    Posted 1 year ago #

    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) :
    http://i0.wp.com/localhost/wp-includes/images/blank.gif

    Address for the Customized AVATAR (which I added / not showing) :
    http://i0.wp.com/localhost/wp-content/themes/catch-box/images/cp2_avatar_membre.jpg

    If I compare this to another image in the site, for ex. the logo in the header, I have this :
    http://localhost:8888/wp-content/uploads/2012/11/cropped-cp2_banner_logo.jpg

    ----> 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,
    Stephanie

  4. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    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

  5. istef8
    Member
    Posted 1 year ago #

    I don't have a jetpack plugin installed... not that I see...

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

  6. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    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!

  7. istef8
    Member
    Posted 1 year ago #

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

    But thank you anyway!

  8. dustinring
    Member
    Posted 1 year ago #

    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 Gravatar.com could not. Make sure you upload your default gravatar to somewhere its API can see.

    More info here: http://blog.gravatar.com/2012/10/09/default-image-changes/

  9. Andrea Barghigiani
    Member
    Posted 1 year ago #

    Hi guys,

    i've tried to use the urlencode() function but is still changing my src into this http://1.gravatar.com/avatar/36598694fda9b579e887781bc48b73c2?s=32&d=%24mioavatar&r=G&forcedefault=1

    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...

Topic Closed

This topic has been closed to new replies.

About this Topic