WordPress支持WebP格式图片上传方法

雨啸青锋 发布于 2020-05-06 861 次阅读


活不多说,直接上代码

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 主题中的functions.php插入这些代码

嘿,大家好,小名尧尧,网名雨啸青锋,00后的小站主,某校高中生
最后更新于 2020-05-06