5

WordPress如何禁止生成缩略图或者特色图像

 2 years ago
source link: https://www.huhexian.com/45627.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

WordPress如何禁止生成缩略图或者特色图像

2022-05-2609:26:53评论

WordPress程序在上传图片后会生成一大推大大小小的缩略图,久而久之服务器资源就会爆满。通过以下代码,可以实现禁止生成缩略图。

WordPress如何禁止生成缩略图或者特色图像
  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. add_action('intermediate_image_sizes_advanced', 'shapeSpace_disable_image_sizes');
  11. // 禁用缩放尺寸
  12. add_filter('big_image_size_threshold', '__return_false');
  13. // 禁用其他图片尺寸
  14. function shapeSpace_disable_other_image_sizes() {
  15. remove_image_size('post-thumbnail'); // disable images added via set_post_thumbnail_size()
  16. remove_image_size('another-size'); // disable any other added image sizes
  17. add_action('init', 'shapeSpace_disable_other_image_sizes');

把这段代码放在你的主题 functions.php 文件即可。

通过以上代码可以禁止绝大部分的缩略图生成,但是文章列表页如果调用了缩略图,还是会默认生成一张 480*300 的缩略图。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK