一、在 设置
-媒体
-媒体设置
中几个尺寸大小的设置不勾选或设置为 0,如下图:
二、找到主题文件 function.php 文件,打开后,在 <?php
后面添加如下代码:
function.php 文件路径一般为:
WordPress网站根目录/wp-content/themes/主题文件夹/functions.php
// 禁用自动生成的图片尺寸
function shapeSpace_disable_image_sizes($sizes) {unset($sizes['thumbnail']); // disable thumbnail sizeunset($sizes['medium']); // disable medium sizeunset($sizes['large']); // disable large sizeunset($sizes['medium_large']); // disable medium-large sizeunset($sizes['1536x1536']); // disable 2x medium-large sizeunset($sizes['2048x2048']); // disable 2x large sizeunset($sizes['750x1000']);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 sizesremove_image_size('kratos-thumbnail'); // disable any other added image sizes,其他缩略图由该模块产生,禁用该模块功能}
add_action('init', 'shapeSpace_disable_other_image_sizes');
三、设置完后去后台媒体中上传一个图片文件试试,是已经不再自动生成不同尺寸的媒体图片。
【本文完!!!】