WordPress彻底禁用上传媒体图片自动生成缩略图及多尺寸图片

将代码添加至您的WordPress当前使用主题文件夹下的functions.php文件即可

以当前网站根目录为例,主题函数文件路径一般为:WordPress网站根目录/wp-content/themes/主题文件夹/functions.php 添加至<?php后面即可

 

// 禁用自动生成的图片尺寸
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');

 

© 版权声明
THE END
請多多支持
点赞13
相关推荐
  • 暂无相关文章
评论 抢沙发

    暂无评论内容