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.

WordPress auto-cropped thumbnails can be deleted manually, preferably completely disabling WordPress’ auto-cropping of 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?add code

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.

//彻底禁止WordPress创建缩略图
 add_filter( 'add_image_size', create_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 ▼

Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "How to Disable WordPress Automatically Generate Thumbnail Cropping Feature?Add Code" to help you.

Welcome to share the link of this article:https://www.chenweiliang.com/cwl-388.html

Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!

🔔 Be the first to get the valuable "ChatGPT Content Marketing AI Tool Usage Guide" in the channel top directory! 🌟
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!

 

Comment

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

scroll to top