Support » Developing with WordPress » ‘default’ Paramater for get_avatar() and get_avatar_url() not working.

  • Evan

    (@skysarwer)


    Hey folks,

    I am working on a customized Buddypress Blogs loop, and I want the blog avatar to return a different image if no Gravatar is found with the site admin email, than the default image returned normally.

    In other words, I am trying to set up an alternative “Default” Gravatar that only applies to one specific section of my website.

    To do this, I am trying to use either the get_avatar() or get_avatar_url() functions, and setting the custom url in the $default parameter as stated in the codex.

     $avatar = 
            '<img src="'.get_avatar_url($blogs_template->blog->admin_user_id, array(
                "size" => "250",
                "default" => $url, 
                )).'" alt="Profile photo of site author">';
            

    This is not working. Setting the default parameter to standard things like “blank”, “mystery” or “404” also do not work. I have been spending a lot of time troubleshooting this, and am starting to wonder if it’s a bug with the function itself.

    Anyone have any ideas?

    Thank you so much!

    • This topic was modified 5 months ago by Evan.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Evan

    (@skysarwer)

    I have also tried

    get_avatar($blogs_template->blog->admin_user_id, 250, $url, 
            'Profile photo of Site Author', array(
                'width'      => $r['width'],
                'height'     => $r['height'],
                'class'      => 'full-width',
            ));

    to no success as well.

    • This reply was modified 5 months ago by Evan.
    Moderator bcworkz

    (@bcworkz)

    Your code works for me when I substitute appropriate values for the variables, assuming $avatar gets echoed out somewhere. Be sure the default URL is publicly accessible. Local paths, intranet paths, etc. don’t work because the URL is still passed through Gravatar. Using ‘monsterid’ and similar also worked as expected.

    Thread Starter Evan

    (@skysarwer)

    That is very strange. The code with simple default values like “mystery”, “monsterid”, etc is not working either. I can confirm that the $avatar variable is being echoed out. The default sticks to the custom default avatar I set up for 90% of the cases. Seems strange that it’s not overriding.

    Moderator bcworkz

    (@bcworkz)

    There are a number of filters involved in the process. Other code on your site could be interfering. Try switching to twentytwentyone theme and deactivating all plugins. Temporarily add your code to one of the theme’s templates for testing. It ought to work if you use reasonable values for the vars and add echo $avatar; to generate output.

    Restore your plugins, one at a time, until your have problems with your code again. The last activated is the cause. If no plugins cause trouble, then the source of trouble was your theme.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.