Disable Unwanted Image Sizes Generation in WordPress

Last Updated on 21 October 2020

Do you know that every single time you upload an file to your WordPress size. The WordPress will automatically generate a tons of images without your notice? If you are notice about it and yes, I’ve came over with solutions.

To stop WordPress from generating the Images, you need to use a child theme and add it to your child theme function.php file.

// Disable WordPress and Woocommerce Image Sizes
function disable_wp_image_sizes( $sizes ) {
    unset( $sizes['thumbnail'] );
    unset( $sizes['medium'] );
    unset( $sizes['medium_large'] );
    unset( $sizes['large'] );
    unset( $sizes['1536x1536']);
    unset( $sizes['2048x2048']);
  
 	// WooCommerce Image Size
    unset( $sizes['woocommerce_thumbnail'] );
    unset( $sizes['woocommerce_single'] );
    unset( $sizes['woocommerce_gallery_thumbnail'] );
    unset( $sizes['shop_catalog'] );
    unset( $sizes['shop_single'] );
    unset( $sizes['shop_thumbnail'] );
    return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'disable_wp_image_sizes');
// Disable Scale Image Sizes
add_filter('big_image_size_threshold', '__return_false');
 
// Disable Other Image Sizes
function disable_wp_other_image_sizes() {
    remove_image_size('post-thumbnail'); // disable images added via set_post_thumbnail_size() 
    remove_image_size('another-size');   // disable any other added image sizes    
}
add_action('init', 'disable_wp_other_image_sizes');

Once you have place the code to the function.php, don’t forget to save it. It will works immediately, I have test it with latest version of WordPress 5.4.