Created
October 12, 2024 06:17
-
-
Save ara303/d7598563789ae1b73e062ad8730b5b45 to your computer and use it in GitHub Desktop.
WordPress remove all but default image sizes
This file contains 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
function only_default_image_sizes(){ | |
foreach( get_intermediate_image_sizes() as $size ){ | |
if( ! in_array( $size, ['thumbnail', 'medium', 'medium_large', 'large'] ) ){ | |
remove_image_size( $size ); | |
} | |
} | |
} | |
add_action( 'init', 'only_default_image_sizes' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A lot of plugins and themes like to register custom image sizes. If you, like me, don't want or need them then when WP generates images resizes down to the custom dimensions specified that takes up a ton of storage space unnecessarily. This removes any image sizes other than WP's defaults.
(I use this all time. 🙂)