How to disable or remove WordPress responsive image markup

WordPress 4.2 introduced a so-called “native” responsive image markup that uses “srcset” and sizes attribute. It’s applied to all images of your blog to serve appropriate thumbnails and images based on the device screen size.

Sometimes you might need to remove WordPress responsive image markup for various purposes and here is the way how to remove or disable it.

Removing WordPress responsive image markup via functions.php

Easily remove the WordPress srcset” and size responsive markup from your WordPress website by editing the functions.php file of your theme.

Add this small code snippet inside the functions.php file, before the ending php tag:

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

 

To prevent WordPress from creating a new medium_large thumbnail in 768px, you will need to add this code to the functions.php file as well.

function ta_customize_thumbnail_sizes($sizes) { 
unset($sizes['medium_large']); // 768px return $sizes; 
} 
add_filter('intermediate_image_sizes_advanced', 'ta_customize_thumbnail_sizes');

After you apply this small tweak, your WordPress website should stop adding responsive markup to the images tag of your blog’s code.

Share this if it was helpful!
davor
davor

I'm Davor, aka. Worda, founder of EleTuts. I hope my articles and guides will help you achieve more with Elementor and WordPress.
My passion is WordPress, plugins and theme development and all-around software development

Articles: 63

Leave a Reply

Your email address will not be published. Required fields are marked *