Article directory
How do I disable WordPress's automatic thumbnail cropping feature?
Most new media professionals will directly add the original images to their articles and will not use images that are 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
Set the width and height of these three images to 0:
- Thumbnail size
- Medium size
- large size
Also, check "Always crop thumbnails to this size".
As shown below:

However, in WP themes, there is usually code to automatically generate thumbnails, what should I do?
Some people say that you can open all the WordPress theme files with Notepad++ , perform a batch search for the keyword "thumbn ail ", and find 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 Weiliang recommends you install and use the Image Sizes plugin ▼
Hopefully, the article "How to disable WordPress's automatic thumbnail cropping feature? Adding code" shared on Chen Weiliang's blog ( https://www.chenweiliang.com/ ) will be helpful to you.
Feel free to share this article's link: https://www.chenweiliang.com/cwl-388.html
