-
-
Save iftee/73cbd9f080c5c7a943cff5e806997f90 to your computer and use it in GitHub Desktop.
<?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' ); | |
?> |
@Salamander3 is correct. Removing those arrays doesn't seem to do anything for me (WP version 4.9.7) but setting the values to 0 in the WP Settings does prevent their creation.
@Salamander3 @jonathanbell + 1
doing nothing for me in 4.9.7, something must have changed in Wordpress core, if this ever worked.
the first unset should have
thumbnail
Yes, I noticed this too.
Can you REALLY unset wp core sizes? I think you just set them to 0x0 which stops creation. They don't disappear like theme created sizes.
I tried setting these to 0x0 and then regenerated thumbnails, and they were still being created and showing up as an option in the WordPress Admin.
doing nothing for me in 4.9.7, something must have changed in Wordpress core, if this ever worked.
It's working fine for me, but I'm on WordPress 5.0.3 for the record.
first time i'm commenting on github
one word: Awesome
How to remove images with dimensions 1536x864
How to remove images with dimensions 1536x864
Add these to remove_default_image_sizes()
:
unset( $sizes['1536x1536'] );
unset( $sizes['2048x2048'] );
and also add these lines to the file:
remove_image_size( '1536x1536' );
remove_image_size( '2048x2048' );
Then, regenerate the images with a plugin like Regenerate Thumbnails.
How to remove images with dimensions 1536x864
Add these to
remove_default_image_sizes()
:unset( $sizes['1536x1536'] ); unset( $sizes['2048x2048'] );
and also add these lines to the file:
remove_image_size( '1536x1536' ); remove_image_size( '2048x2048' );
Then, regenerate the images with a plugin like Regenerate Thumbnails.
Thank you very much @swinggraphics
I defined the function, but whenever I go on the Regenerate Thumbnails page, I can still see '1536x1536' and '2048x2048'. WHat am I doing wrong? https://pastebin.com/fPJYuADG
This works! Also, WP generates an image with suffix -scaled
. How can remove it too?
Better, how can remove all images sizes without specifying them one by one? In this way we would be sure we never have image sizes WP could add in the future.
@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.
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;
Can you REALLY unset wp core sizes? I think you just set them to 0x0 which stops creation. They don't disappear like theme created sizes.