Last update at :2024-03-21,Edit by888u
This site found that recently WordPress will automatically generate 1536×1536 and 2048×2048 size images for uploaded images. After checking, we found that WordPress 5.3 has added large images with these two resolutions by default. If the image you upload exceeds If this resolution is reached, images of these two sizes will be cropped from the original image. However, images of this size are not usually used at all, so today I will share how to disable WordPress to automatically generate images of this size.
1. How to disable cropping images in WordPress
Just add the following code to functions.php. The code will disable WordPress from generating 1536×1536 and 2048×2048 size images:
function remove_default_image_sizes( $sizes) { unset( $sizes['1536x1536']); unset( $sizes['2048x2048']); return $sizes; } add_filter('intermediate_image_sizes_advanced', 'remove_default_image_sizes');The reason for this problem: WordPress 5.3 introduced additional image sizes which can be found via /wp-includes/media.php.
That is, WordPress 5.3 has added large images with these two resolutions by default. If the image you upload exceeds this resolution, the image of these two sizes will be cropped on the original image, and WordPress 1536×1536 and The two sizes of WordPress 2048×2048 are generally not used, and the cropped image is larger than the original image. The recommended measure is to ban it directly.
2. More ways to disable thumbnails in WordPress
WordPress will generate thumbnails of many different sizes by default. Some sizes are not used at all and do not need to be used. When building the website, the following settings are generally made in [Media Settings] (0 means no corresponding ones will be generated) thumbnail):
There is also a code on the Internet that directly disables all WordPress thumbnails, which can also be placed in functions.php:
// Disable automatically generated image sizes 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'); //Disable scaling add_filter('big_image_size_threshold', '__return_false'); // Disable other image sizes 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');Recommended site searches: US servers and Japanese servers, mainland China domain names, foreign PHP hosts, ASP free space, PHP host space, Taiwan servers, Hong Kong proxy servers, virtual host spaces, website ICP filing, the latest free proxy IP, < /p>
发表评论