Upload WebP image in WordPress without Plugins.

WebP Image

It is an image format employing both lossy and lossless compression. WebP image is supports animation and alpha transparency and this type image format Developed by Google.

How to upload WebP Image in WordPress

If WebP image not suppot to upload in WordPress, so Add given code in functions.php file of your WordPress Theme. When you Pasted this code in functions.php file then WordPress will enable to upload WebP Image.

function webp_upload_mimes( $existing_mimes ) {
// add webp to the list of mime types
$existing_mimes['webp'] = 'image/webp';
// return the array back to the function with our added mime type
return $existing_mimes;
}
add_filter( 'mime_types', 'webp_upload_mimes' );
//** * Enable preview / thumbnail for webp image files.*/
function webp_is_displayable($result, $path) {
if ($result === false) {
$displayable_image_types = array( IMAGETYPE_WEBP );
$info = @getimagesize( $path );
if (empty($info)) {
$result = false;
} elseif (!in_array($info[2], $displayable_image_types)) {
$result = false;
} else {
$result = true;
}
}
return $result;
}
add_filter('file_is_displayable_image', 'webp_is_displayable', 10, 2);