[Support request] Elements Page Hero serve WebP

Home Forums Support [Support request] Elements Page Hero serve WebP

Home Forums Support Elements Page Hero serve WebP

  • This topic has 3 replies, 2 voices, and was last updated 1 year ago by Elvin.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1475394
    Eric

    Is there a way to serve a webp file that Imagify creates in the elements page hero to up my Google PSI score? What I am thinking is that in the css it could serve a webp background image first and then the jpg. Or if there is a way to serve it so imagify can rewrite the image to a picture with both options.

    #1475422
    Elvin
    Staff
    Customer Support

    Hi,

    By default, WordPress doesn’t allow WebP files on to be uploaded on its media library. But you can still definitely do it by adding this PHP snippet.

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

    Reference: https://mariushosting.com/how-to-upload-webp-files-on-wordpress/

    Alternatively, you can convert already uploaded jpg files to webp by using a third party plugin.
    Read more here – https://kinsta.com/blog/webp/

    A wise man once said:
    "Have you cleared your cache?"

    #1475484
    Eric

    Will this serve a webp with a jpg fallback?

    #1475491
    Elvin
    Staff
    Customer Support

    Will this serve a webp with a jpg fallback?

    I’m afraid the snippet is only for allowing you to directly upload your WebP files to the WordPress media library.

    Custom image fallbacks to its jpg version will require third party plugins like the one you mentioned. (Imagify)

    As to what’s the best among the plugins, I’m afraid I can’t pinpoint them for you as they’re outside GeneratePress support’s scope.

    A wise man once said:
    "Have you cleared your cache?"

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.