Last active
November 18, 2020 21:52
-
-
Save jnicol/fea17641b9f8a87432fea2964aa646d5 to your computer and use it in GitHub Desktop.
Remove WordPress default image sizes to save disk space
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function remove_default_image_sizes( $sizes) { | |
// sizes defined in media settings | |
unset( $sizes['thumbnail']); | |
unset( $sizes['medium']); | |
unset( $sizes['large']); | |
// auto-generated images since WP 5.3 | |
unset( $sizes['medium_large']); | |
unset( $sizes['1536x1536']); | |
unset( $sizes['2048x2048']); | |
return $sizes; | |
} | |
add_filter('intermediate_image_sizes_advanced', 'remove_default_image_sizes'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Comment out the sizes you want to keep.
ALWAYS keep thumbnail and medium image sizes: WP uses them for thumbnails in the media library and will fall back to full size image if medium images don't exist.