The latest version of WordPress, 4.4 (“Clifford”), has rolled out a feature whereby it adds ‘srcset’ attributes to all image tags in order that browsers can decide which image to load if various resolutions are available.
This is all well and good, but (a) you may not want these new attributes in your code for a variety of reasons, and (b) conflicts with some plugins and themes are being reported.
In either case, you may need an easy way to disable the feature, for the time being at least.
Here is such a way, courtesy of StackExchange user Birgir Erlendsson.
add_filter('wp_get_attachment_image_attributes', function($attr) { if (isset($attr['sizes'])) unset($attr['sizes']); if (isset($attr['srcset'])) unset($attr['srcset']); return $attr; }, PHP_INT_MAX); add_filter('wp_calculate_image_sizes', '__return_false', PHP_INT_MAX); add_filter('wp_calculate_image_srcset', '__return_false', PHP_INT_MAX); remove_filter('the_content', 'wp_make_content_images_responsive');
Just add this code to your theme’s functions.php file and you’re done. But make sure you’re running PHP 5.3 or later before adding it.