• 916VT

    (@vincent916)


    Hi there,

    I can’t change my default avatar image. I found this code and a lot of quite similare versions that I’ve tried :

    add_filter( 'avatar_defaults', 'newgravatar' );
    function newgravatar ($avatar_defaults) {
        $myavatar = get_bloginfo('template_directory') . '/images/own-gravatar.jpg';
        $avatar_defaults[$myavatar] = "Own";
        return $avatar_defaults;
    }

    But on the backoffice discussion page and on the comment area, the image is not displayed. The return src url is :

    https://1.gravatar.com/avatar/3923c5b0606e373cb28b02f249064f2f?s=80&d=http%3A%2F%2F((mysite))%2Fwp-content%2Fthemes%2Frttw_v2%2Fimg%2Favatar.jpg%3Fs%3D80&r=G

    I don’t know where the first part is coming from. It looks to work for thousand of WP users…

    Anyone has an idea to fix ?

    Thanks a lot for your help !

Viewing 14 replies - 16 through 29 (of 29 total)
  • Yeah, that won’t work because Gravatar can’t access your localhost site. Try a URL that actually exists.

    Thread Starter 916VT

    (@vincent916)

    I tried online, but it brokes my theme/site. I have everywhere :

    Parse error: syntax error, unexpected T_FUNCTION in /home/scarades/rttw/wp-content/themes/rttw_v3/functions.php on line 212

    The full code :

    /*
     * New default avatar
     */
    add_filter( 'avatar_defaults', 'custom_default_avatar' );
    function custom_default_avatar ( $avatar_defaults ) {
    $new_avatar_url = get_stylesheet_directory_uri() . '/img/avatars.jpg';
    $avatar_defaults[$new_avatar_url] = 'New Default Gravatar';
    return $avatar_defaults;
    }
    add_filter( 'pre_option_avatar_default', function( $value ) {
    	return 'https://mysite.com/wp-content/themes/rttw_v2/img/avatar.jpg';
    } );

    Looks like you’re running a very old version of PHP. Try a newer version or don’t use an anonymous function with the filter:

    add_filter( 'pre_option_avatar_default', 'my_pre_option_avatar_default' );
    function my_pre_option_avatar_default( $value ) {
    	return 'https://mysite.com/wp-content/themes/rttw_v2/img/avatar.jpg';
    }

    Also, you don’t need the first part with the avatar_defaults filter and the custom_default_avatar function.

    Thread Starter 916VT

    (@vincent916)

    So you say I have to use only that part ?

    add_filter( 'pre_option_avatar_default', 'my_pre_option_avatar_default' );
    function my_pre_option_avatar_default( $value ) {
    	return 'https://mysite.com/wp-content/themes/rttw_v3/img/avatar.jpg';
    }

    Because the website came back but the avatar url return again :

    https://1.gravatar.com/avatar/3923c5b0606e373cb28b02f249064f2f?s=80&d=http%3A%2F%2Fmysite.com%2Fwp-content%2Fthemes%2Frttw_v3%2Fimg%2Favatar.jpg%3Fs%3D80&r=G

    The code looks fine and the Gravatar URL looks correct, assuming that you’re using an image file that actually exists, and not mysite.com.

    Thread Starter 916VT

    (@vincent916)

    The url going to the image avatar.jpg works fine when it’s copy/paste on a tab.

    And your last code works in local but keep broking the theme online…

    Same mistake :

    Parse error: syntax error, unexpected T_FUNCTION in /home/scarades/rttw/wp-content/themes/rttw_v5/functions.php on line 217

    Okay, let’s try it again. Please share the complete code that you’re using in production. Please keep all URLs as they are, without changing anything to mysite.com or yoursite.net, and also send me a link to a comments page on your site.

    Thanks.

    Thread Starter 916VT

    (@vincent916)

    The website is not yet live but you can find the functions.php file here :

    https://dl.dropboxusercontent.com/u/10351694/Theme/functions.php

    I could make a special session for you if you like to see the backoff.

    That looks fine, and here’s the Gravatar URL that redirects to your default image just fine: https://1.gravatar.com/avatar/3923c5b0604e373cb28b02f249064f2f?s=80&d=https://riding-through-this-world.com/wp-content/themes/rttw_v2/img/avatar.png&r=G

    Unless I’m missing something, it works as expected.

    Thread Starter 916VT

    (@vincent916)

    On local, yes, it looks to work just fine.

    But when I sent the full folder with FTP to my site hoster, I’m getting the error message that I shared above. And it’s exactly the same files.

    Can you post the full functions.php file again from your hoster? Did you use the closure function(){} or the my_pre_option_avatar_default as in my second example?

    Thread Starter 916VT

    (@vincent916)

    Functions is back to the hoster.

    It’s the second example :

    /*
     * New default avatar
     */
    add_filter( 'pre_option_avatar_default', function( $value ) {
    	return 'https://site.com/wp-content/themes/rttw_v3/img/avatar.jpg';
    } );

    Yeah, that’s my first example. Try this one without anonymous functions instead:

    add_filter( 'pre_option_avatar_default', 'my_pre_option_avatar_default' );
    function my_pre_option_avatar_default( $value ) {
    	return 'https://mysite.com/wp-content/themes/rttw_v3/img/avatar.jpg';
    }

    Also tell your hoster to upgrade PHP.

    Thread Starter 916VT

    (@vincent916)

    Hi Konstantin,

    You were right about the php version. I got it uprgrade from 5.2 to 5.5.

    Also, the last code works fine for avatars anymore.

    But I still have an issue with comments : when I use the test address, once I wrote and validate a comment, the page doesn’t load up with the comment. It’s not displayed and I need to reload the page to see it. It works when I’m connect as admin. So it looks like a wrong set up of discussion, but I should have at least the message about moderation (which is even not necessary because if you reload, the comment is there).

    May we broke something with the code above ? It does not look related at all.

    Thanks a lot for your help (again)

Viewing 14 replies - 16 through 29 (of 29 total)
  • The topic ‘Issue for changing Mystery Man avatar’ is closed to new replies.