WordPress Tutorials

Upload webp Images in WordPress without any Plugins

Recently, Google has introduced a new image file format called WebP. WebP is a next-generation image file format, It compresses image files up to 35% smaller in size without losing any quality. Google recommends to use this file format to increase your website speed, But the problem is we are unable to up-load image file to WordPress and many of us are using WordPress. Here is the solution to upload



Copy The Below Code and Paste in Your Function File, watch the video for more help.

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);

Tutorial Video ;

Thanks,

HIVEcorp.

Leave a Reply

Your email address will not be published. Required fields are marked *