WordPress 开启 webp 格式支持的方法

主机教程 wordpress教程评论145字数 539阅读1分47秒阅读模式

webp是Google出的一种图片格式,是一种同时提供了有损压缩与无损压缩(可逆压缩)的图片文件格式,派生自影像编码格式VP8,被认为是WebM多媒体格式的姊妹项目,是由Google在购买On2 Technologies后发展出来,以BSD授权条款发布。

wordpress logo 1文章源自国外主机测评-https://www.zjcp.org/2789.html

WordPress支持webp,能对文件体积大幅度减小。文章源自国外主机测评-https://www.zjcp.org/2789.html

在网站的主题 functions.php 文件中加入下面的代码即可:文章源自国外主机测评-https://www.zjcp.org/2789.html

//支持webp文件上传
function webp_filter_mime_types($array)
{
    $array['webp'] = 'image/webp';
    return $array;
}
add_filter('mime_types', 'webp_filter_mime_types');

//支持在后台媒体管理中显示webp文件
function webp_file_display($result, $path) {
    $info = @getimagesize( $path );
    if($info['mime'] == 'image/webp') {
        $result = true;
    }
    return $result;
}
add_filter( 'file_is_displayable_image', 'webp_file_display');
文章源自国外主机测评-https://www.zjcp.org/2789.html文章源自国外主机测评-https://www.zjcp.org/2789.html
 
  • 本文由 主机测评 发表于 2022年12月6日22:30:00
  • 转载请务必保留本文链接:https://www.zjcp.org/2789.html

发表评论