WordPress怎么上传webp格式图片?支持WebP格式图片上传方法

火币

火币

火币是全球三大交易所之一,虚拟货币交易平台安全可靠,注册领取新人礼包!

图片[1]-WordPress怎么上传webp格式图片?支持WebP格式图片上传方法-玩转网 | 902D.Com

话不多少,直接上代码

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插入这些代码

© 版权声明
THE END
点赞12赞赏 分享