Table of Contents
If you are using WordPress when you upload an image it will automatically generate six images of varying sizes. WordPress generating multiple sizes is a little bit pointless especially when you’re not going to use those images as it will take your hosting space.
There is a simple way to disable it in a simple way without a plugin. And luckily this post will explain how to disable WordPress from generating various image sizes automatically with two methods, without a PHP code and with a PHP code inside your theme function.php.
Disable Generating Auto Image Sizes Without Coding
To prevent WordPress from generating different image sizes after uploading an image, follow these steps:
Log into WordPress with the Administrator role account.
On the Dashboard in the left sidebar, go to Settings, and go to Media (see the screenshot below).
In the Media Settings, set the width and height to zero for Thumbnail size, Medium size, and Large size.
Click on Save Changes, to save the changes.
Disable Generating Auto Image Size with Coding to Your function.php
If you want to completely disable all the image sizes, insert this code to your function.php
function disable_media($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', 'disable_media');
add_filter('big_image_size_threshold', '__return_false');
You might also want to add this to set the size to zero to disable WordPress from generating images when you activated your theme
if (isset($_GET['activated']) && is_admin()) {
update_option('posts_per_page', 12);
update_option('thumbnail_size_w', 0);
update_option('thumbnail_size_h', 0);
update_option('thumbnail_crop', 1);
update_option('medium_size_w', 0);
update_option('medium_size_h', 0);
update_option('medium_large_size_w', '0');
update_option('medium_large_size_h', '0');
update_option('large_size_w', 0);
update_option('large_size_h', 0);
}
That’s it, now WordPress won’t autogenerate all the images you upload from now on.
If you want WordPress to generate a thumbnail with the sizes you set, insert this code.
// This will set your thumbnail size to 421x263.
add_image_size('bigthumb', 421, 263, true);