分享Wordpress中禁止上传图片生成多个尺寸版本的方法。
1、登录wordpress后台,在设置–媒体里,把三个规格的宽度和高度数值全部改为0。
2、将代码复制粘贴到主题functions.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');
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');
再次上传图片,就会发现只有原图,不会再生成任何其他版本了。
本文是全系列中第13 / 14篇:优化加速
- 利用七牛云对象存储+CDN服务,给WordPress网站静态文件加速
- 推荐几款WordPress清理优化插件
- 清理不必要WordPress数据优化数据库插件:Easy WP Cleaner
- wordpress如何开启Memcached缓存加速
- 优化WordPress文章过多导致网站卡顿
- 让WP Rocket速度更快的小技巧 :更适合Nginx服务器
- 清理WordPress中数据库冗余数据的方法
- wordpress删除文章修订版本和自动草稿而残留的数据
- WordPress图像优化插件:Plus WebP
- lnmp 开启 Opcache 脚本缓存提高 php 性能
- 使用OpenLiteSpeed+LiteSpeed cache优化加速Wordpress网站
- WordPress设置QUIC.Cloud免费CDN图文教程
- WordPress禁止上传图片生成多个尺寸版本
- WordPress开启Redis缓存加速