Discover in this tutorial how to avoid generating too many thumbnails in WordPress using a simple code snippet.
WordPress creates by default 3 thumbnails of different sizes for each image you upload to the library. And that’s not counting the ones that some themes and plugins produce on their own…
Do you know what this means?
That, depending on the combination of child theme and plugins you’re using, it’s possible that 15-20 different thumbnail sizes are being generated.
And this is far from efficient as it increases the size of the database and the weight of the installation (specifically the /uploads/ folder).
Do you want to solve this problem by preventing certain thumbnail sizes from being generated?
Or all of them, but let the choice be yours. 😉
Then read on. And remember, less is more.
Snippet to block the creation of thumbnails in WordPress
1. In a simple WordPress installation
Add the following code at the end of functions.php or in your functionality plugin:
Here you use the
intermediate_image_sizes_advanced filter to prevent certain thumbnail sizes from being created.
2. In a WooCommerce installation
If you have a WooCommerce and you also want to save the generation of thumbnails, the following code would be more suitable than the previous one:
3. Custom thumbnail deletion
As I said in the introduction, the type and number of thumbnails you have depends on the Genesis child theme and plugins you use.
So, first of all, I recommend you to install the Regenerate Thumbnails plugin to identify them, as it tells you:
- Number of thumbnails.
- Size of the thumbnails.
- Name of the thumbnails.
Here’s a pretty “loaded” WordPress installation:
Now imagine this is your WordPress installation and you want to remove the registration and creation of all thumbnails
This would be the snippet you should use
You can see that once you understand the logic and know the name of the thumbnails, it is very easy to adapt this tutorial to your needs.
4. Check the thumbnails by ftp
The most effective way to make sure that the images you upload stop generating more thumbnails than you want is to check the /wp-content/uploads/year/month/ folder via ftp.
If you use a snippet that unregisters all thumbnail sizes you should only see a single file when uploading an image.
For example, the image widget-testimonial-2.jpg is uploaded after disabling all thumbnail sizes. That’s why only one version appears.
In contrast, the widget-testimonial-1.jpg has all the other sizes because this snippet had not yet been applied when it was added
And speaking of this…
Important: This code only affects images that you upload to WordPress after implementation, i.e. it does not affect files that are previously uploaded to the library
And if you want to get new thumbnails and delete all the ones you’ve deleted, use Regenerate Thumbnails.
With a few lines of code you can keep the amount of thumbnails created in your or your client’s WordPress installation at bay.
Make a good planning of the sizes that will be necessary and thus avoid creating redundant (or useless) versions that only serve to overload your website.
Any questions? I read you in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉