Stop WordPress from Creating Multiple Thumbnail Size Images
Here is a head start that is really important and you should take into consideration if you still haven’t set up your blog yet. By default, WordPress duplicates the images that you upload into 4 different sizes (thumbnail, medium, medium-large, and large) while uploading, and your theme and/or plugin(s) may create more sizes. This is a major issue when you are considering storage space, but there are solutions to this.
The Easiest and Fastest Ways to Stop Generating Image Sizes (No Coding Experience Needed)
- Login to Your WP Dashboard.
- Go to Settings and then, Media.
- Here you will find 3 various image sizes: thumbnail, medium, large. Decide which image sizes you won’t be using and then set those sizes to 0.
- Update and save your new settings.
Once you are done, check your theme, as many WordPress themes have their own set of image sizes that it will generate.
You can do this by using an FTP client like FileZilla and scan through the directory marked /wp-content/uploads/ to see if this is the case.
If you don’t know how to use an FTP client, then you can look for the following source code in your functions.php file to see if your theme is kicking out additional pictures that you don’t need.
- Go to your WP Dashboard.
- Navigate to Appearance and then, Editor.
- Find your theme’s function.php file and click on it (find it on the right-hand side).
- Search for the following code: add_image_size and/or set_post_thumbnail_size. If the .PHP file contains that code it will appear there and that means that your theme is generating images. If no image_size source code is shown, then you are lucky.
If you find that your .PHP file has the above-mentioned code, then you need to delete the code and update your files to cut those out.
Once done editing the code of your theme file, you should go to Appearance » Editor. Go ahead and edit your functions.php file from here.
You need to delete a few lines of code from this file that represents the default image sizes. It may look similar to this code below:
set_post_thumbnail_size( 1200, 9999 );
add_image_size( 'homepage-thumb', 220, 180, true );
In the above code, the two functions set_post_thumbnail_size and add_image_size allow your theme to generate additional image sizes. Deleting the code prevents the theme from adding more images in WordPress. If you are going to implement this, make sure you are adding the code in the child theme, as adding the code in the main theme file might be overridden by the theme providers once the theme is updated. To create a child theme for your website, check this article on How to Create a WordPress Child Theme.
Stop Generating Image Sizes Through Adding a Code to functions.php
Simply navigate to Appearance » Editor » functions.php and add the below code.
function add_image_insert_override($sizes){
unset( $sizes['thumbnail']);
unset( $sizes['medium']);
unset( $sizes['large']);
return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'add_image_insert_override' );
Stop Generating Image Sizes Using a Plugin
Stop generating image sizes plugin is one of several plugins that can take care of this issue for you.
If you are facing issues with uploading files to your WordPress site, learn How to Increase the WordPress Maximum Upload File Size.
Using Custom Code to Remove Image Sizes
Another way to prevent WordPress from generating unnecessary image sizes is by removing them through custom code. Add the following code to your theme’s functions.php file:
function remove_default_image_sizes( $sizes) {
unset( $sizes['thumbnail']);
unset( $sizes['medium']);
unset( $sizes['medium_large']);
unset( $sizes['large']);
unset( $sizes['1536x1536']);
unset( $sizes['2048x2048']);
return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'remove_default_image_sizes' );
Utilizing the Regenerate Thumbnails Plugin
If you have already uploaded images and want to remove the existing sizes, you can use the Regenerate Thumbnails plugin. This plugin allows you to delete old thumbnails and regenerate new ones based on your current settings.
- Install and activate the Regenerate Thumbnails plugin.
- Go to Tools » Regenerate Thumbnails.
- Select the options to delete old thumbnails and click on the Regenerate Thumbnails button.
Advanced Techniques: Leveraging WP-CLI
If you are comfortable using the command line, you can use WP-CLI to remove unnecessary image sizes. WP-CLI is a powerful tool for managing your WordPress site from the command line.
# List all image sizes
wp media image-size
# Regenerate thumbnails
wp media regenerate --only-missing
# Remove old thumbnails
wp media regenerate --only-missing --skip-delete
By using these techniques, you can significantly reduce the number of unnecessary image files on your WordPress site, saving storage space and improving site performance.