Skip to content

Instantly share code, notes, and snippets.

@ara303
Created October 12, 2024 06:17
Show Gist options
  • Save ara303/d7598563789ae1b73e062ad8730b5b45 to your computer and use it in GitHub Desktop.
Save ara303/d7598563789ae1b73e062ad8730b5b45 to your computer and use it in GitHub Desktop.
WordPress remove all but default image sizes
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' );
@ara303
Copy link
Author

ara303 commented Oct 12, 2024

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. 🙂)

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