How to enable Webp format support in WordPress

888u

Last update at :2024-07-12,Edit by888u

webp is an image format developed by Google. It is an image file format that provides both lossy compression and lossless compression (reversible compression). It is derived from the image encoding format VP8 and is considered a sister project of the WebM multimedia format. , developed by Google after purchasing On2 Technologies, and released under BSD license terms.

Let WordPress support webp, which can greatly reduce the file size.

Add the following code to the website's theme functions.php file:

//Support webp file upload
function webp_filter_mime_types($array)
{
    $array['webp'] = 'image/webp';
    return $array;
}
add_filter('mime_types', 'webp_filter_mime_types');

//Support displaying webp files in background media management
function webp_file_display($result, $path) {
    $info = @getimagesize( $path );
    if($info['mime'] == 'image/webp') {
        $result = true;
    }
    return $result;
}
add_filter( 'file_is_displayable_image', 'webp_file_display');

Recommended site searches: Telecom server rental, US website space, domain name reverse check, Hong Kong vps, legendary server rental, Hong Kong IP, registration network, server space rental, foreign server rental, Taiwan host,

How to enable Webp format support in WordPress

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码