WebP Image Upload in WordPress

Webp upload wordpress- If you want to save the storage space on your server, using the WebP format every time you want to upload an image is a reasonable reason. An image with the extension of .webp is 25% smaller in size than other formats like JPG and PNG.

Add the following code to the function.php file.

//enable upload for webp image files.
 function webp_upload_mimes($existing_mimes) {
     $existing_mimes['webp'] = 'image/webp';
     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);