How to disable responsive images in WordPress 4.4

Published 11 Dec 2015 in PHP & MySQL, Responsive Design, Themes, WordPress by ZigPress

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. On 13 Dec 2015 at 08:48, Nick Johnston said:

    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. On 13 Dec 2015 at 11:37, ZigPress said:

    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. On 21 Dec 2015 at 17:41, Melissa said:

    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. On 03 Jan 2016 at 10:40, Dude said:

    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. On 06 Jan 2016 at 07:21, Robin Khokhar said:

    Thanks for providing the coding.

  6. On 20 Jan 2016 at 07:08, Bryan Eggers said:

    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. On 21 Jan 2016 at 12:35, simon beasley said:

    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. On 22 Jan 2016 at 01:00, Niloy Sarker said:

    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. On 28 Jan 2016 at 10:32, Jennifer said:

    Great thanks for coding, its very useful.

  10. On 14 Feb 2016 at 14:11, Scott said:

    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. On 19 Feb 2016 at 22:20, britney said:

    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. On 24 Jun 2016 at 01:06, Maria Fernandes said:

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