WordPress禁止生成缩略图小白教程!

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

禁用方法

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

  1. // 禁用自动生成的图片尺寸
  2. function shapeSpace_disable_image_sizes($sizes) {
  3. unset($sizes['thumbnail']);// disable thumbnail size
  4. unset($sizes['medium']);// disable medium size
  5. unset($sizes['large']);// disable large size
  6. unset($sizes['medium_large']);// disable medium-large size
  7. unset($sizes['1536x1536']);// disable 2x medium-large size
  8. unset($sizes['2048x2048']);// disable 2x large size
  9. return $sizes;
  10. }
  11. add_action('intermediate_image_sizes_advanced', 'shapeSpace_disable_image_sizes');
  12. // 禁用缩放尺寸
  13. add_filter('big_image_size_threshold', '__return_false');
  14. // 禁用其他图片尺寸
  15. function shapeSpace_disable_other_image_sizes() {
  16. remove_image_size('post-thumbnail');// disable images added via set_post_thumbnail_size()
  17. remove_image_size('another-size');// disable any other added image sizes
  18. }
  19. add_action('init', 'shapeSpace_disable_other_image_sizes');

发表评论

后才能评论

评论(1)