4

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.

  • have you tried with the get_avatar filter? – Tomás Cot Sep 2 '14 at 16:58
  • Got this problem as well when testing locally so its not Jetpack. – Brad Dalton Sep 2 '14 at 17:34
7
+100

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)
  • How about for adding a custom image pulled from the child theme folder? – Brad Dalton Sep 2 '14 at 19:05
  • 1
    Any local default image will be redirected to i2.wp.com/some/path/to/a/local/image with the message "We cannot complete this request, remote data was invalid". @BradDalton Do you mean how to use a public default image from a child theme? – birgire Sep 2 '14 at 19:20
  • 1
    In the above comment I meant local as in not public. @BradDalton Is your image public? – birgire Sep 2 '14 at 19:31
  • 2
    worked like a charm, thank you so much birgire. There's a 17 hour time limit on the bounty, I'll be sure to reward it then. – Anindya Basu Sep 2 '14 at 22:55
  • 1
    One thing to note. When customizing default avatar for an SVG graphic: you need to hook get_avatar_url filter and define the graphic url there because point 3 "MUST have a recognizable image extension (jpg, jpeg, gif, png)" isn't fullfilled – ZalemCitizen Oct 5 at 12:10
0

This is because of Photon addon you enabled in JetPack plugin. That's why your image URLs will be like...

> http://i0.wp.com/image-url
> http://i1.wp.com/image-url
> http://i2.wp.com/image-url

You will get any of these three URLs. It's WordPress's free CDN services. Which is great.

The problem is that you are trying it on localhost that's why it's not working. Because WordPress CDN or any other CDN can not pull images from localhost. You should try it on online server. Just disable photon and everything will be fine :)

Word of advice, never turn on CDN services on localhost. You will get into errors.

EDIT: By default it should have something like...

http://0.gravatar.com/avatar/...

But in your case it's using http://i2.wp.com/ which must be caused by a plugin or you added some code in functions.php.

Did you added code in functions.php to return all images from http://i2.wp.com/. This must also be a case.

  • 2
    I do not have the jetpack plugin. – Anindya Basu Aug 29 '14 at 16:36
  • Did you try disabling all plugins? You can disable all plugins by renaming plugin folder to plugin_backup. – Robert hue Sep 2 '14 at 17:44
  • I had a similar problem that was caused by the PageSpeed Apache module. – Flimm Jun 22 '17 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.