admin管理员组

文章数量:1124692

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.

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.

Share Improve this question edited Mar 16, 2013 at 17:38 brasofilo 22.1k8 gold badges69 silver badges264 bronze badges asked Mar 16, 2013 at 15:06 DanielDaniel 1891 gold badge1 silver badge3 bronze badges 2
  • Please turn off any plugins and switch to your default theme. Then you should be able to set all image sizes to 0 and keep WP from generating those sizes. If this doesn't work, please report back. If it works, then there's some plugin or theme interfering. – kaiser Commented Mar 17, 2013 at 11:33
  • You can use the plugin Stop Generating Unnecessary Thumbnails. WordPress doesn't generate thumbnail when uploading images or set featured image and image doesn't make image cropping with folder image upload where make add size or number of files hosting. – ahdan ahmad Commented Jul 27, 2021 at 2:12
Add a comment  | 

10 Answers 10

Reset to default 14

You can also filter intermediate_image_sizes with an empty array.

 add_filter( 'intermediate_image_sizes', '__return_empty_array' );

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

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

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.

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.

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.

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

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;
}

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

In my case, it wasn't enough to disable the generating of thumbnails neither in admin nor in the code.

Then I found a great plugin.

ThumbPress – Stop Generating Unnecessary Thumbnails (by Codexpert, Inc)

本文标签: How to disable WordPress from creating thumbnails