How to disable responsive images srcset in WordPress

In current article going to let you How to disable responsive images srcset in WordPress ?
From WordPress 4.4 new release version WordPress added a cool new responsive feature to automatically handle all uploaded images. If yor website running with WordPress 4.4 or latest version look at Page view source, you can see image tag hold one more attribute scrset, Basically, scrset attributes are added to each image so browsers can decide what image size to apply based on specific device resolution and screen size. scrset feature very useful in show images responsive,

In Some specific reason if you want to disable it in your or your client wordpress website here is a quick way to disable srcset feature in WordPress

Just add below simple few line code to your active theme functions.php file and you can see now images loading withour srcset attribute.

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

To remove srcset for specific location used post thumbnail use below code

remove_filter( 'wp_calculate_image_srcset_meta', '__return_null' ); // Remove that filter 
the_post_thumbnail();  // Display post thumbnail
add_filter( 'wp_calculate_image_srcset_meta', '__return_null' ); // add srcset filter back




Leave a Comment

Scroll to Top