WordPress禁止生成缩略图

2023-05-16 13:10:34 浏览数 (3)

WordPress默认不关闭上传以上图片会生成多个版本的缩略图,不管你用不用,时间久了网站Ftp占用爆表。建议禁用WordPress默认生成缩略图功能。

禁用方法

将下边的代码放到主题 functions.php 文件内即可生效

代码语言:javascript复制
// 禁用自动生成的图片尺寸
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');

百度未收录

0 人点赞