In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
这篇文章给大家分享的是有关 WordPress支持WebP格式图片的方法的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。
WordPress 默认不支持WebP格式图片上传,将下面代码添加到当前主题函数模板functions.php中,即可解决上传问题。
function webp_filter_mime_types( $array ) {$array['webp'] = 'image/webp';return $array;}add_filter( 'mime_types', 'webp_filter_mime_types', 10, 1 );function webp_upload_mimes($existing_mimes) { $existing_mimes['webp'] = 'image/webp'; return $existing_mimes;}add_filter('mime_types', 'webp_upload_mimes');
虽然已经可以上传WebP格式的图片了,但在媒体列表中看不到缩略图,这是因为WordPress在用 wp_generate_attachment_metadata()函数生成图片数据时,使用了file_is_displayable_image()函数判断文件是否为图片,判断WebP图片的结果为否,因此中断了保存图片数据的操作。
该函数位于:wp-admin/includes/image.php展开
解决办法是在主题的functions.php里添加以下代码:
function webp_file_is_displayable_image($result, $path) {$info = @getimagesize( $path );if($info['mime'] == 'image/webp') {$result = true;}return $result;}add_filter( 'file_is_displayable_image', 'webp_file_is_displayable_image', 10, 2 );function webp_is_displayable($result, $path) {if ($result === false) {$displayable_image_types = array( IMAGETYPE_WEBP );$info = @getimagesize( $path );if (empty($info)) {$result = false;} elseif (!in_array($info[2], $displayable_image_types)) {$result = false;} else {$result = true;}}return $result;}add_filter('file_is_displayable_image', 'webp_is_displayable', 10, 2);
文本中的插图就是webp图片,虽然目前七牛、又拍云、阿里云oss、腾讯云cos等都支持WebP,不过发现苹果设备并不支持webp图片,包括IOS版的微信,这也可能是WordPress一直不支持webp图片的原因吧。
感谢各位的阅读!关于 WordPress支持WebP格式图片的方法就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.