Dean Williams

How to disable srcset responsive images in WordPress

You are currently viewing the Mobile Optimized version (AMP), some features may be missing or may not work as expected. Open Full 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' );

 

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