How to disable responsive images in WordPress 4.4

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.

12 Comments

  1. Is there a way to make this filter retroactively applicable only to posts from a certain date going backwards (like from the date of 4.4 update back to the beginning of our blog)?

    For reasons too complicated to explain, I can’t have responsive images in any posts until a few months prior to the 4.4 update, but I’d like to retain the functionality for new posts if possible.

  2. Off the top of my head, you could probably put the code inside the init action and wrap it in an if statement that checks the post date.

  3. Thank you so much for this – I have been so frustrated by the way my already responsive site suddenly looked on iPad – 4.4 is causing Safari to pull 200 px wide images and scale up instead of the 700 px wide originals I had in the post. I will share this solution with a few others I know that are having the same problem.

  4. Hi, omg you are a life saver! I have a masonry theme and it was causing havoc on firefox but chrome & ie were ok. Thank you so much!

  5. Thanks for providing the coding.

  6. I just want to confirm that this code not only prevents WP from adding the attributes but also prevents WP from making all the extra images.

    My /upload directory went from 90meg to 6gig when I upgraded to 4.4! Thanks

  7. thanks for this, my issue is that the wp 4.4 responsive images changes automatically create a srcset attribute that uses https rather than http (the real site url in the wp_options db field). this is causing mixed content error message and images are not displaying across the whole site, which is a major problem. I can’t find any comments from people experiencing the same problem

  8. A huge Thanks to you for this article .
    i even don’t know about ‘srcset’ until right now.
    i was trying to create a jquery slider but when i was tried to convert it in wordpress plugin then it was conflict every time i was trying to fixed it.
    But Now The issue is Gone.
    hurryy!!

  9. Great thanks for coding, its very useful.

  10. Hi,

    I added this code to my functions.php in my child theme, but can’t see any difference.

    Is there anything else to do other than add the code?

    I’ve got the issue on bluefinchphotography.co.uk/test

    Thanks

  11. hank you so much for this – I have been so frustrated by the way my already responsive site suddenly looked on iPad – 4.4 is causing Safari to pull 200 px wide images and scale up instead of the 700 px wide originals I had in the post. I will share this solution with a few others I know that are having the same problem.

  12. Thank you so much for sharing this, as i was looking for this issue from few days. Thanks again.

Add a Comment

If you have used this form and would like a copy of the information held about you on this website, or would like the information deleted, please email info@zigpress.com.