Improve WordPress loading speed by controlling Gravatars

When we get to optimize the loading speed of WordPres s one of the parameters that you have to control are all the resources that we serve from external URLs, especially those that contain request chains .

And many times we blame plugins and even the subject – rightly so – of the burden of these external resources, not optimally.

But it turns out that nothing else install WordPress, and by default, without changing any settings, we are already serving resources from external services through the known as url query strings Do you know what I mean?

The Gravatares are the devil, do not you?

To the gravatars to that Automattic service, which serves the avatars of the users who comment, even our own user avatar.

In the comments settings of your WordPress, just install it, it is active loading avatars from and this load makes every time there is a registered user , for example, or a comment in an entry, generate external requests through query strings to the service m, to know which avatar to show for this or that email

I think you're already imagining the amount of requests you can generate in an entry of … let's say … 60 comments?

Someone will tell me " well, if nobody comments in blogs ", but yes you generate requests even if you have few comments but multiply, or go through the comment management screen of your WordPress, what do you see a few? That's it.

I'm not even telling you if you have forums or a social network with BuddyPress.

The Solomonic solution

Now I would put academic and in mode developer to suggest some code or function, but in reality it is very easy to get rid of all this we are talking about.

You just have to go to your WordPress desktop at Settings> Comments and disable the avatars. You save the changes and you're done,

Nice, right?

The best thing is that this setting applies even if you're using comments from JetPack or similar systems .

What's left cute?

Developer mode ON

Now do not you want to be so radical? We put on our work overalls and we're going to be something finer.

The idea is, at least, that they do not generate URL query strings from gravatars so they take less in loading the requests and, incidentally, we have some more affection Google PageSpeed ​​and give us a better score.

What we will try to do is that WordPress does not make requests of the type http: //0.gravatar .com / avatar / 5uuywc88e00be0c94f480326043b9b4c17711? s = 120 & d = default & r = x

Method 1

To get remove that type of parameters from the requests to Gravatar you have to add the following code to your function plugin :

Method 2

Sometimes the above code will not work. I mean if you use any solution (or theme) that uses calls to get_avatar () with custom image elements.

I mean when your plugin, theme or whatever (you messing around) you use something like this:

In these cases the code to be used would be the following:

The result of one method and another has nothing to do, of course, but as always you choose. ] Loading …

That may also help you: