How To Upload WebP Files on WordPress - eCommerce Thesis

How To Upload WebP Files on WordPress

WebP is a modern image format employing both lossy and lossless compression. WebP helps webmasters and web developers to create smaller, richer images that make the web faster.

It makes the website SEO friendly. As a professional eCommerce web developer. I always use WebP formate image in my client’s web design project and always recommended to my follow or beginners use this format.

But there is an issue when you will try to upload in your website that builds with WordPress

If you’ve tried to upload a Webp file to your media library and received the “Sorry, this file type is not permitted for security reasons” error, you may feel stumped as to how to proceed. Below I will explain how to solve the problem.

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


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

If you need any support relavent WordPress then you can hire me at Fiverr

Some of my services include:

Website Setup
Demo Theme Setup
Plugins Setup
Theme Customization
Page Post Create
Update Pages
Fix Responsive Issues.
Speed Optimisation
Design Optimisation
SEO Optimisation
Backups and Migration
WordPress Errors Fixing
Fixing Error Establishing Database Connection
Plugin Issues Fixing
Fixing Theme Issues
Website Security
SSL Certificate Add with Green Padlock
Live Chat Messenger Integrate
Full eCommerce site using WooCommerce

I will provide you Professional Support as your requirements. I’m super organized, seeking a happy customer, and will be delighted to work for you, and hopefully, in no time I will fix, edit, customize your website 🙂

Leave a Reply