WebP 是谷歌即将推出的适合于 Web 使用的图像格式,在保持同样质量的情况下,可比 JPG 减小 40% 的体积。
目前主流浏览器都支持Webp,您可以点击https://caniuse.com/#search=webp查看
因此,我决定在以后尽可能多使用webp,以减小占用空间、减短加载时常。
但在我上传WebP图像时,Wordpress提示:
抱歉, 由于安全原因, 这个文件类型不受支持。
这是由于WordPress 没有把 WebP 当成图片来看待,首先需要修改 wp-includes/functions.php 文件。
搜索 gif
在下面添加一行
'image/webp' => 'webp', 继续搜索
添加一行 ‘image/webp’ ==>'webp' 保存,退出 然后在主题的function.php(/wp-content/themes/xxx) 加入:
//webp
function bzg_filter_mime_types( $array ) {
$array['webp'] = 'image/webp';
return $array;
}
add_filter( 'mime_types', 'bzg_filter_mime_types', 10, 1 );
function bzg_file_is_displayable_image($result, $path) {
$info = @getimagesize( $path );
if($info['mime'] == 'image/webp') {
$result = true;
}
return $result;
}
add_filter( 'file_is_displayable_image', 'bzg_file_is_displayable_image', 10, 2 );
退出,保存。
请注意不要加在最下面 请加在中间
随后,Wordpress便支持WebP了,本站头图就是webp格式,占用很小
参考资料:

