How to disable WordPress from creating thumbnails?

I've been looking around the net for a long time on how to disable WordPress from creating multiple thumbnails.

I've seen in most tutorials to set all the images to 0 in the media section. I have done that, but going to my uploads folder and it still creates multiple images.

I can't find any solution for this. The reason I want this is to save space on my host account.

Topic thumbnails post-thumbnails images Wordpress

Category Web


If you want to remove everything just returns an empty array.

function remove_thumbnail_image_sizes($sizes) {
    return [];
}
add_filter('intermediate_image_sizes_advanced','remove_thumbnail_image_sizes');

Since Wordpress often have WooCommerce installed this disables the image regeneration when put into a functions.php (for example in a child theme or via a code snippet plugin since it may otherwise be overwritten on updates).

add_filter( 'woocommerce_background_image_regeneration', '__return_false' );

I've run into trouble using the intermediate_image_sizes_advanced filter on a few sites lately. It seems like in WP 5.3 intermediate_image_sizes is more reliable.

I would recommend unsetting unwanted sizes like this:

add_filter('intermediate_image_sizes', 'remove_default_img_sizes', 10, 1);

function remove_default_img_sizes($sizes)
{
    $targets = ['medium', 'medium_large', 'thumbnail'];

    foreach ($sizes as $size_index=>$size) {
        if (in_array($size, $targets)) {
            unset($sizes[$size_index]);
        }
    }

    return $sizes;
}

For the latest WordPress with WooCommerce activated plugin use this code:

function add_image_insert_override($sizes){
    unset($sizes['thumbnail']);
    unset($sizes['medium']);
    unset($sizes['medium_large']);
    unset($sizes['large']);
    unset($sizes['1536x1536']);
    unset($sizes['2048x2048']);        
    unset($sizes['blog-isotope']);
    unset($sizes['product_small_thumbnail']);
    unset($sizes['shop_catalog']);
    unset($sizes['shop_single']);
    unset($sizes['shop_single_small_thumbnail']);
    unset($sizes['shop_thumbnail']);
    unset($sizes['woocommerce_thumbnail']);
    unset($sizes['woocommerce_single']);
    unset($sizes['woocommerce_gallery_thumbnail']);
    return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'add_image_insert_override' );
add_filter('max_srcset_image_width', create_function('', 'return 1;'));

But it would be great if you leave one small thumbnail (thumbnail) and one middle-sized image (medium).

P.S. You can see all registered sizes by installing Regenerate Thumbnails plugin. And don't forget about add_image_size() generating on the theme side.


To built on Max Yudin's answer you should use the intermediate_image_sizes_advanced filter, and not image_size_names_choose. Add to functions.php

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' );

Another easier option I think works is going to your Settings-->Media and setting each box for width and height to 0


If I remember right you have to unset all the defaults and add the new Size there:

    <?php
function mxdCustomImageSizes($sizes) {
    unset( $sizes['thumbnail']);
    unset( $sizes['medium']);
    unset( $sizes['large']);
    unset( $sizes['full'] );

    $myimgsizes = array(
        'full-size' => __( 'Full Size' )
    );
    if( !empty($sizes) )
        return array_merge($sizes, $myimgsizes);
    else
        return $myimgsizes;
}
add_filter('intermediate_image_sizes_advanced', 'mxdCustomImageSizes');

And then add the full-size size which is 99999x99999 right below which size is almost unbelievable so is full size.

add_image_size( 'full-size', 99999, 99999, false );

Please correct me if something goes wrong

P. S. You'll need a plugin to "save as" all your images according to your new settings. I can recommend the Regenerate Thumbnails plugin.

P. P. S. When it's the single Option any way you'll have to choose one of one :). There no straight way to make one Size selected in the new (3.5.1) Media window.


function remove_default_image_sizes( $sizes) {
    unset($sizes['thumbnail']);
    unset($sizes['medium']);
    unset($sizes['large']);
    return $sizes;
}
add_filter('intermediate_image_sizes_advanced','remove_default_image_sizes');

Don't forget to return $sizes; like this.

Then add new image sizes like...

if(function_exists('add_image_size')){
    add_image_size('my_100x100_crop',100,100,true); // Crop mode
    add_image_size('my_100x100_resize',100,100); // Resize mode
}

Tested!


Visit the Settings > Media page of your WordPress dashboard. Under the Image Sizes section, change all of the values to 0.

Media Settimgs

Save the changes. This will stop WordPress generating thumbnails, medium, and large sizes of every image you upload.

You will also notice that when you go to insert an image, the "Size" dropdown box is missing.


You can also filter intermediate_image_sizes with an empty array.

 add_filter( 'intermediate_image_sizes', '__return_empty_array' );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.