contacts

Get All 146 Premium WordPress Themes for Just $59.99
One-Time Payment: Unlimited Use Across Unlimited Domains, Plus Free Lifetime Updates! Learn more

How to fix “Sorry, this file type is not permitted for security reasons” for WebP image in WordPress

How to fix “Sorry, this file type is not permitted for security reasons” for WebP image in WordPress

If you upload a WebP image to WordPress media library, you will receive the following error:

Sorry, this file type is not permitted for security reasons

The above can be fix with a small code change. Here are all of the necessary steps:

1. Login to your Admin Panel

2. Navigate to Left Menu -> Appearance -> Theme Editor

3. Open functions.php for edit

4. At the end of the file, insert the following code:


function tishonator_webp_upload_mimes($existing_mimes) {
    $existing_mimes['webp'] = 'image/webp';
    return $existing_mimes;
}
add_filter('mime_types', 'tishonator_webp_upload_mimes');


function tishonator_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', 'tishonator_webp_is_displayable', 10, 2);

5. Save changes