Skip to content

Instantly share code, notes, and snippets.

@iftee
Last active November 12, 2022 00:21
Show Gist options
  • Save iftee/73cbd9f080c5c7a943cff5e806997f90 to your computer and use it in GitHub Desktop.
Save iftee/73cbd9f080c5c7a943cff5e806997f90 to your computer and use it in GitHub Desktop.
Custom filter to remove default image sizes (WordPress and WooCommerce) from your theme.
<?php
/*
* Custom filter to remove default image sizes from WordPress.
*/
/* Add the following code in the theme's functions.php and disable any unset function as required */
function remove_default_image_sizes( $sizes ) {
/* Default WordPress */
unset( $sizes[ 'thumbnail' ]); // Remove Thumbnail (150 x 150 hard cropped)
unset( $sizes[ 'medium' ]); // Remove Medium resolution (300 x 300 max height 300px)
unset( $sizes[ 'medium_large' ]); // Remove Medium Large (added in WP 4.4) resolution (768 x 0 infinite height)
unset( $sizes[ 'large' ]); // Remove Large resolution (1024 x 1024 max height 1024px)
/* With WooCommerce */
unset( $sizes[ 'shop_thumbnail' ]); // Remove Shop thumbnail (180 x 180 hard cropped)
unset( $sizes[ 'shop_catalog' ]); // Remove Shop catalog (300 x 300 hard cropped)
unset( $sizes[ 'shop_single' ]); // Shop single (600 x 600 hard cropped)
return $sizes;
}
add_filter( 'intermediate_image_sizes_advanced', 'remove_default_image_sizes' );
?>
@aschultzapiam
Copy link

@dangelion the only way I can see to prevent the "-sclaed" images from being created is to use the filter "big_image_size_threshold" and return a large value (px) for threshold. The default is "2560" pixels so setting it to something like "10000" would probably prevent the image from being created in most scenarios.

@aschultzapiam
Copy link

I also noticed there is another version of the image it sometimes creates with the suffix "-rotated", If you want to prevent these then use the filter 'wp_image_maybe_exif_rotate' and return false;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment