I have updated wordpress using the following code to allow for webp uploads,
function webp_upload_mimes( $existing_mimes ) {
$existing_mimes['webp'] = 'image/webp';
return $existing_mimes;
}
add_filter( 'mime_types', 'webp_upload_mimes' );
Which works great, but the webp images do not show a preview in the media selector, as shown
Is there anyway I can force wordpress to render webp previews? By the time my site is done, it could potentially have hundreds of webp images, not being able to see them when selecting could be a huge pain!
I found a solution to show the thumbnails on the media manager. You have to add the following code to the
functions.php
of your active theme:The
webp_is_displayable
function is using thefile_is_displayable_image
hook and checks if the file (on$path
) is awebp
image file. To check for thewebp
image file the function is using the constantIMAGETYPE_WEBP
.