wordpress的webp解决方案

发布于 2020-04-13  1938 次阅读


wordpress的webp解决方案

1. 使wordpress支持webp

在wordpress主题functions.php添加如下代码

function mimvp_filter_mime_types( $array ) {
    $array['webp'] = 'image/webp';
    return $array;
}
add_filter( 'mime_types', 'mimvp_filter_mime_types', 10, 1 );
function mimvp_file_is_displayable_image($result, $path) {
    $info = @getimagesize( $path );
    if($info['mime'] == 'image/webp') {
        $result = true;
    }
    return $result;
}
add_filter( 'file_is_displayable_image', 'mimvp_file_is_displayable_image', 10, 2 );

2. 使用webp批量转换工具生成webp

软件下载(蓝奏云)
依赖下载(蓝奏云)
食用方法,,下载软件和依赖,在软件目录新建lib文件夹,放入依赖运行软件即可


努力决定态度,态度决定高度.