How to disable WordPress auto-generated thumbnail cropping feature?add code

How to disableWordpressAutomatically generate thumbnail crop function?

mostnew mediaPeople will add original pictures directly in the article, and they will not use the pictures automatically cropped by wordpress.

Although cropped images are useless, WordPress will not automatically delete them. Over time, these "junk images" waste a lot of website space capacity, and at the same time add a lot of pressure to backup.

We can manually delete the thumbnails that WordPress automatically crops, but it is best to completely disable the WordPress function of automatically cropping images.

Disable WordPress auto-generated thumbnail cropping feature

Open the WordPress options mode (WP background click [Settings] –> [Multimedia Options])
www.xxx com/wp-admin/options-media.php

put thisThe length and width of the 3-size images are all set to 0:

  1. Thumbnail size
  2. Medium size
  3. large size

Also, check "Always crop thumbnails to this size".

As shown below:

How to disable WordPress auto-generated thumbnail cropping feature?

However, in WP themes, there is usually code to automatically generate thumbnails, what should I do?

Some people say that it can be opened with Notepad++All wordpress theme files.Bulk searchKeyword "thumbail", found the following code:

function set_post_thumbnail_size($width= 0,$height= 0,$crop= false ) {
add_image_size(‘post-thumbnail’,$width,$height,$crop);
}

This is the code that sets the crop size of the image and calls add_image_size This function function.

The function of the add_image_size function:

  • Registering a new image size means that you upload a new image and WordPress will create a new featured image of that size.

If you want to completely disable WordPress from automatically cropping thumbnails, you have to kill this function!

The easiest way is to find this function and comment it out.

However, this method sucks and needs to be re-commented every time the WordPress theme is updated...

By searching, you can find some ways to prohibit a certain function on the Internet, and copy the following code into the WordPress theme functions.php file, you can completely prohibit the automatic generation of thumbnail cropping function of wordpress.

// 禁用自动生成的图片尺寸
function shapeSpace_disable_image_sizes($sizes) {
unset($sizes['thumbnail']); // disable thumbnail size
unset($sizes['medium']); // disable medium size 
unset($sizes['large']); // disable large size 
unset($sizes['medium_large']); // disable medium-large size 
unset($sizes['1536x1536']); // disable 2x medium-large size 
unset($sizes['2048x2048']); // disable 2x large size return $sizes;
}
add_action('intermediate_image_sizes_advanced', 'shapeSpace_disable_image_sizes');
// 禁用缩放尺寸
add_filter('big_image_size_threshold', '__return_false');
// 禁用其他图片尺寸
function shapeSpace_disable_other_image_sizes() {
remove_image_size('post-thumbnail'); // disable images added via set_post_thumbnail_size()

remove_image_size('another-size'); // disable any other added image sizes
}
add_action('init', 'shapeSpace_disable_other_image_sizes');

If you think the above code is too much, or choose 2 from 1, do not add the above code, only add the following code▼

// 彻底禁止 WordPress 缩略图
add_filter( 'add_image_size', function() { return 1; } );
  • In fact, this is to insert a return in the function and deprecate the function.

remove medium_large_size_w

When WordPress 4.4 is installed/updated, the "medium_large_size_w" size will be written into the options, resulting in a 768w pixel thumbnail that will always be generated later.

Of course, the previous solution is to modify the database, which is not very convenient.

Open the WordPress options mode (WP background click [Settings] –> [All Settings])
www.xxx com/wp-admin/options.php

Then press Ctrl+F in the browser to search:

medium_large_size_w
  • After finding it, change the value to 0, then pull to the bottom of the page, and click [Save Changes].

Although the way to add WordPress code to disable WordPress automatically generates thumbnail cropping, it is still not comprehensive enough...

Chen WeiliangIt is recommended that you install and use Image Sizes plugin ▼

Comment

Your email address will not be published. Required fields * Callout

Scroll to Top