功能介绍

有时候特色图像经过默认WordPress或者主题功能裁剪之后总感觉达不到心目中的预期,启用该功能之后彻底禁止WordPress自动生成缩略图的方法,含主题和系统自带缩略图策略!

配置教程

首先利用宝塔或则FTP打开/inc/options下的admin-options.php文件把下面代码放在20行左右

  1. array(
  2. ‘id’ => ‘is_wp_thumbnail’,
  3. ‘type’ => ‘switcher’,
  4. ‘title’=> ‘禁止WP生成缩略图’,
  5. ‘label’ => ‘启用后彻底禁止WP自动生成缩略图的方法 含主题和系统自带缩略图策略’,
  6. ‘default’ => false,
  7. ),

最后在主题根目录下打开functions.php将以下代码放在最后即可

  1. //+———————————————————————-
  2. //| 禁用WP自动生成的图片尺寸
  3. //+———————————————————————-
  4. if(_cao(‘is_wp_thumbnail’)){
  5. function cnwper_disable_image_sizes($sizes) {
  6. unset($sizes[‘thumbnail’]); // disable thumbnail size
  7. unset($sizes[‘medium’]); // disable medium size
  8. unset($sizes[‘large’]); // disable large size
  9. unset($sizes[‘medium_large’]); // disable medium-large size
  10. unset($sizes[‘1536×1536’]); // disable 2x medium-large size
  11. unset($sizes[‘2048×2048’]); // disable 2x large size
  12. return $sizes;
  13. }
  14. add_action(‘intermediate_image_sizes_advanced’, ‘cnwper_disable_image_sizes’);
  15.  
  16. // 禁用缩放尺寸
  17. add_filter(‘big_image_size_threshold’, ‘__return_false’);
  18.  
  19. // 禁用其他图片尺寸
  20. function cnwper_disable_other_image_sizes() {
  21.  
  22. remove_image_size(‘post-thumbnail’); // disable images added via set_post_thumbnail_size()
  23. remove_image_size(‘another-size’); // disable any other added image sizes
  24.  
  25. }
  26. add_action(‘init’, ‘cnwper_disable_other_image_sizes’);
  27. }