How to save storage space by deregistering and deleting unused WP image size variations

Warning: Only follow this guide, if you know what you’re doing. Deregistering and deleting image variations can lead to missing images and broken links. Many themes and plugins are registering and using more than the default WordPress images sizes. Please backup your files and database before starting this process.

  1. Hosting isn’t this expensive anymore, non the less it can be useful to only store image variants your WordPress site really needs.

Overview of all registered sizes:

To see which sizes are registered in the first place, you can simply install a plugin called “Regenerate Thumbnails“. Then simply navigate to the plugin menu and you’ll see an overview like this:

Given this information and based on your setup, you can now decide which sizes your site really needs.

Deregister not needed sizes:

Deregistering sizes is going to take care about not making new image size variations on future image uploads. This can be achieved by add this code snippet to your themes functions.php:

/* Deregistering image sizes by name */
add_filter('intermediate_image_sizes', function($sizes) {
  return array_diff($sizes, ['large', 'medium_large']);

/* Deregistering image sizes by size */
add_action( 'init', 'tk_remove_image_sizes' );
function tk_remove_image_sizes() {
  remove_image_size( '1536x1536' );
  remove_image_size( '2048x2048' ); 


Deleting already saved images:

Deleting all images that have been generated before deregistering given sizes can be done…

…via pluging
Good for a smaller amount of images in the uploads folder. Can take very long if you have a lot of media.

…via ssh
Good for big/huge amount of media files.

I personally prefer the ssh solution:

Login to your server via ssh and run the following command: find ./uploads/* -iname ‘*-1536×1536.*’ -exec rm {} \;

This will delete all images containing the String “-1536×1536.” in their filename. You can repeat this process for every image size you want to delete.

Be careful: Sometimes you or a user uploads an image that’s called “car-1536×1536.jpg” in the first place. Even though this is then the original images size, it’ll be deleted by using this command. 

Leave a Comment