WordPress support WebP

Topic can be found on official site

Extra code to go to the functions.php

Uploading WebP images to WordPress?  Just add snippet to theme functions.php file.

//** *Enable upload for webp image files.*/
function webp_upload_mimes($mimes) {
    $mimes['webp'] = 'image/webp';
    return $existing_mimes;
}
add_filter('mime_types', 'webp_upload_mimes');

To see image (thumbnail) preview when you go Media / Library you have to add this code below in the same functions.php file.

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

Was this article helpful?

Related Articles

Leave A Comment?