Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Remove SRCSET from FV Gravatar Cache WordPress


Hello experts.

I've installed a plugin called FV Gravatar Cache which caches gravatar icon.

It works, but there's one thing that I'd like to change which is removing SRCSET and its URL from the output. Currently the full output is as follow:

<img alt='' src='//' srcset=';d=mm&amp;r=g 2x' class='avatar avatar-80 photo' height='80' width='80' />

So I'd like exclude "srcset=';d=mm&amp;r=g 2x'" from the output.

You can see the live example at my website:


Additional Information:

I found that if I modify the Wordpress core file pluggable.php from wp-includes, removing srcset='%s' from line 2395 and also removing esc_attr( "$url2x 2x" ), then it will no longer show the srcset.

I am looking for a more elegant way to remove the srcset rather than modifying the core files.

Answers (3)


Reigel Gallarde answers:

you can try this on your functions.php

if( get_option( 'fv_gravatar_cache') ) {
add_filter( 'get_avatar', 'custom_get_avatar', 11);

function custom_get_avatar( $image ) {

if( is_admin() ){
return $image;

$image = preg_replace( '/srcset=(["\'])[^\1]*?\1/i', '', $image, -1 );

return $image;

raymond comments:

Added your code to functions.php but the srcset of gravatar is still there.

Reigel Gallarde comments:

I change the preg_replace.. it was wrong... please check now...

Reigel Gallarde comments:

this should be the correct preg_replace...

$image = preg_replace( '/srcset=(["\'])[^\1]*?\1/i', '', $image, -1 );

I updated above to reflect to this...

raymond comments:

Thanks it works perfectly.


Arnav Joy answers:

please write this jquery in footer.php of your theme


raymond comments:

Thanks but sorry I am looking for a server side solution.
I don't want to rely on a browser side solution such as using Javascript to remove it.


Hiro Hito answers:

You can edit the plugin and remove the attribute directly, but the edits will be overwritten if you update it in future