You may have already visited my previous post on how to Prevent Your WordPress Post Image Being Too Large. In this post I’ll explain you how to remove redundant image sizes and files.
As you may already know each WordPress theme has a bundle of image sizes, and every time we switch theme, we’ll use other image sizes. That will lead us to a problem of redundant image files left in WordPress folder! They occupy a large space of our host, and make us hard to do a backup because of unacceptable running time and file size.
Take a look at this diagram. There are total 6 files generated from one uploaded image with different size.
Here are three steps to avoid this.
1) Remove registered image sizes, you have to delete the code in your WordPress theme/plugin that registers image sizes and which you don’t need, like this:
add_image_size( 'crunchify-thumbnail', 200, 90, true );
Another must read:
2) You might want to remove built-in thumbnail sizes: thumbnail
, medium
, large
. They’re registered by WordPress by default and you can’t remove them with the technique above. There’s a trick in this case: put zero 0
in thumbnail sizes (width and height) will disable these sizes. Put below code to functions.php file.
update_option( 'thumbnail_size_h', 0 ); update_option( 'thumbnail_size_w', 0 ); update_option( 'medium_size_h', 0 ); update_option( 'medium_size_w', 0 ); update_option( 'large_size_h', 0 ); update_option( 'large_size_w', 0 );
3) If you are on VPS hosting/ Dedicated Hosting and have root access then you can execute below command to remove unnecessary images.
find . -name *-280x110.* | xargs rm -f
Above command will find all images with width size 280 and height size 110. Make sure you do full backup before executing above script.