How to disable srcset responsive images in WordPress

There is a Mobile Optimized version of this page (AMP). Open Mobile Version.

As far back as WordPress 4.4 a feature has been included which can take original images and automatically decide to introduce a srcset for various sizes of images to fit responsive versions of the site, the problem is that you might not have a responsive site, or like us you might have fairly large source images, but you choose for example a 200x200 size for the image fixed, what WordPress does is actually generate a ton of srcset images based on the original image dimensions even though your only using that 200x200 in the document. Which makes this feature extremely broken and detrimental.

Luckily you can very easily disable this feature by adding this into your themes functions.php:

function remove_max_srcset_image_width( $max_width ) {
    return false;
}
add_filter( 'max_srcset_image_width', 'remove_max_srcset_image_width' );

function wdo_disable_srcset( $sources ) {
    return false;
}
add_filter( 'wp_calculate_image_srcset', 'wdo_disable_srcset' );

 

Facebooktwitterredditpinterestlinkedinmail

Author: Dean Williams

I'm a Web Developer, Graphics Designer and Gamer, this is my personal site which provides PHP programming advice, hints and tips

Post Tags:
,
0 0 vote
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments