Last active
July 4, 2021 08:09
-
-
Save mbparvezme/beab467188ed63ff8b79f97018b57d59 to your computer and use it in GitHub Desktop.
Upload WebP image files to Wordpress
This file contains hidden or 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
// --- TESTED WITH WordPress 5.3.2 | |
// --- ADD BELLOW CODE TO function.php | |
//** Enable upload for webp image files */ | |
function webp_upload_mimes($existing_mimes) { | |
$existing_mimes['webp'] = 'image/webp'; | |
return $existing_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); | |
add_filter('mime_types', 'webp_upload_mimes'); |
Works perfect, thank you
Thank you. But this is not my writing. I collected it here after getting it online. But unable to remember the source.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works perfect, thank you