How to Prevent WordPress from Generating Image Sizes

152

By default, WordPress generates three sizes of each image that you upload. Themes and plugins can generate additional image sizes which can easily push the number between 5 – 10. If you have a lot of image based content on your site, then after a while this may increase your storage needs and backup file size. In this article, we will show you how to prevent WordPress from generating image sizes.

Why and When You Need to Prevent WordPress From Generating Image Sizes

First thing you should keep in mind is that the default image sizes are not harmful for your website. Most WordPress hosting providers offer generous disk space enough to store thousands of images.

The additional image sizes are generated and stored during the upload process, so they do not affect website visitors in any way. If you are having trouble with handling images or post thumbnails, then instead of switching them off you can learn how to solve some common image issues.

Having said that, some users may want to prevent WordPress from generating image sizes. For example, if you have thousands of images, then the copies of these images could make your backup sizes extremely large. It would also become time consuming for your backup plugin to prepare and store backups to the cloud. Lastly, if you don’t see yourself using some of the available image sizes, then disabling them will save you space.

Stopping WordPress From Generating Image Copies in Different Sizes

First you need to understand how many copies of an uploaded image are generated by WordPress. By default WordPress generates three image sizes, for thumbnail, medium, and large. Apart from these image sizes, your WordPress theme may also have its own image sizes for featured image/post thumbnails, sliders, and other features.

You need to connect to your website using an FTP client to find out how many copies of an image your WordPress site is generating.

Start by uploading an image to your site from your WordPress admin area. Next, connect to your website using an FTP client, or use cPanel’s file manager. Now go to /wp-content/uploads/ directory. The image file you upload are stored in year and month based directory. Once you are in the directory, you will see all images generated by WordPress.

Images stored for different image sizes in WordPress

As you can see in the screenshot above, our demo WordPress installation is generating 5 copies of each image. Three of these images are the default WordPress image sizes thumbnail, medium, and large. Other two sizes are generated by the theme.

You can stop WordPress from generating default image sizes by visiting Settings » Media in WordPress admin area. There you will see default image sizes predefined by WordPress. You need to set these sizes to 0 which will prevent WordPress from generating default image sizes when you upload a new image.

Setting the default image sizes to zero in WordPress

Note: WordPress uses the thumbnail image size for galleries, so if you set that to 0, then your future gallery display may not work properly.

The other two image sizes are generated by the WordPress theme. You can usually find the theme size code in your theme’s functions.php file. Simply look for the code line containing add_image_size function. It will look something like this, and there could be multiple lines depending on how many image sizes your theme supports:

  add_image_size( 'homepage-thumb', 220, 180, true );

Removing these lines will stop your theme from generating those image sizes.

You also need to find the line containing set_post_thumbnail_size function. It will look something like this:

  set_post_thumbnail_size( 150, 150 );

Removing this line will stop your theme from generating post thumbnail size in WordPress.

Please note that these image sizes may be used by your theme for post thumbnails, sliders, attachments, or custom post types. Only remove them if you are certain and well aware of the effect this might have on your site.

We hope this article helped you prevent WordPress from generating image sizes and keep your uploads directory clutter free. For feedback and questions, you can leave a comment below, or join us on Twitter and Google+.