Last active
October 27, 2021 05:33
-
-
Save topmask/80b512b21a69d963b89f9d012f0b43ed to your computer and use it in GitHub Desktop.
Enable upload for webp image files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//** *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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment