Enable Webp in WordPress and increase performance.

WebP is a modern image format that provides superior lossless and lossy compression for images on the web. Using WebP, webmasters and web developers can create smaller, richer images that make the web faster.

WebP lossless images are 26% smaller in size compared to PNGs. WebP lossy images are 25-34% smaller than comparable JPEG images at equivalent SSIM quality index.

Lossless WebP supports transparency (also known as alpha channel) at a cost of just 22% additional bytes. For cases when lossy RGB compression is acceptable, lossy WebP also supports transparency, typically providing 3× smaller file sizes compared to PNG.

Lossy WebP compression uses predictive coding to encode an image, the same method used by the VP8 video codec to compress keyframes in videos. Predictive coding uses the values in neighboring blocks of pixels to predict the values in a block, and then encodes only the difference.

Lossless WebP compression uses already seen image fragments in order to exactly reconstruct new pixels. It can also use a local palette if no interesting match is found.

You’ll notice if you try uploading a .webp format image into your media library, it isn’t allowed. This is because it isn’t a recognised MIME type in WordPress, yet.

How do we enable it now?

Easy. Add the following code to your functions.php file and away you go!


<?php
if ( ! function_exists( 'uncoverwp_webp_upload_mimes' ) ) :
    /**
     * Enable webp for enhanced performance
     */
    function uncoverwp_webp_upload_mimes( $existing_mimes )
    {
        $existing_mimes['webp'] = 'image/webp';
        return $existing_mimes;
    }
    add_filter( 'mime_types', 'uncoverwp_webp_upload_mimes' );
endif;

Conclusion

Google loves a fast website, and adding little snippets like this will help you to make yours as fast as possible!

UncoverWP

Want us to email you occasionally with our latest courses, news & updates?

We use cookies to ensure that we give you the best possible experience on our website. If you continue to use this site we will assume that you are happy with it. OK Privacy Policy