I’m trying to upload a custom Gravatar to WordPress, however something is breaking the image link and I’m not sure how to fix it.

add_filter( 'avatar_defaults', 'new_default_avatar' );

function new_default_avatar ( $avatar_defaults ) {
    //Set the URL where the image file for your avatar is located
    $new_avatar_url = get_bloginfo( 'template_directory' ) . '/img/icons/avatar.jpg';
    //Set the text that will appear to the right of your avatar in Settings>>Discussion
    $avatar_defaults[$new_avatar_url] = 'New Default Gravatar';
    return $avatar_defaults;
}

The code works, because I get a radio button with the option to add the Gravatar. The only thing that is broken is the actual image.

When I right click on the image I get this URL:

http://i2.wp.com/localhost/wordpress/wp-content/themes/blog-theme/img/icons/avatar.jpg

I’m not sure where i2.wp.com is coming from, or what it’s doing. When I remove that and do

loalhost:888/wordpress/wp-content/themes/blog-theme/img/icons/avatar.jpg

I can see the Gravatar image.

When I googled this, I saw a lot of people have this problem because of the Jetpack and Photon plugins, but I do not have any plugins installed.

2 s
2

I think the problem is simply that your default avatar isn’t publicly available.

Try for example

http://upload.wikimedia.org/wikipedia/en/b/b0/Avatar-Teaser-Poster.jpg

instead of

http://loalhost:888/wordpress/wp-content/themes/blog-theme/img/icons/avatar.jpg

Notice that the default gravatar is served via http{|s}://i{0,1,2}.wp.com/...

From the docs:

When you include a default image, Gravatar will automatically serve up that
image if there is no image associated with the requested email hash. There are a > few conditions which must be met for default image URL:

  • MUST be publicly available (e.g. cannot be on an intranet, on a local
    development machine, behind HTTP Auth or some other firewall etc). Default
    images are passed through a security scan to avoid malicious content.
  • MUST be accessible via HTTP or HTTPS on the standard ports, 80 and 443,
    respectively.
  • MUST have a recognizable image extension (jpg, jpeg, gif, png)
  • MUST NOT include a querystring (if it does, it will be ignored)
Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *