Site logo

[Support request] webp

Home Forums Support [Support request] webp

Home Forums Support webp

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1557062
    Howard

    Hi:
    Would this be proper code to enter WEB P image to generatepress theme editor?

    //** *Enable upload for webp image files.*/
    function webp_upload_mimes($existing_mimes) {
    $existing_mimes[‘webp’] = ‘image/webp’;
    return $existing_mimes;

    Also: would it just be pasted on the NEXT LINE AT THE BOTTOM of theme editor and saved?
    Thanks
    Howard

    #1557071
    Elvin
    Staff
    Customer Support

    Hi,

    Yes your PHP snippet is pretty close, but it seems to be missing the filter where its suppose to apply to.

    Its also missing a } to close the function which is pretty important as it can cause syntax errors.

    Here’s a more complete version of your code:

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

    Please refer to this on how to add PHP snippets to your site – https://docs.generatepress.com/article/adding-php/

    #1557080
    Howard

    Thanks- I will just paste it to my “Code Snippets” app

    Howard

    #1557088
    Elvin
    Staff
    Customer Support

    No problem. 🙂

    #1557095
    Howard

    Hi
    Another question
    ( more complicated)
    How to fix:

    Ensure text remains visible during webfont load
    Leverage the font-display CSS feature to ensure text is user-visible while webfonts are loading.

    I know there are code(s) ..
    But where and how to apply them ( novice)
    Howard

    #1557114
    Elvin
    Staff
    Customer Support

    Hi,

    Let’s try to keep it 1 issue per topic.

    That said, can you open up a new one for your other questions? Thank you. 🙂

    #1558700
    Howard

    Hi: This code does not seem to work when put into CODE SNIPPETS

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

    #1559386
    Elvin
    Staff
    Customer Support

    Hi,

    This part seems to be missing some codes.

    ...
    add_filter(‘file_is_displayable_image

    You have to add the function name(webp_is_displayable), priority (10) and # of accepted args(2).

    add_filter('file_is_displayable_image', 'webp_is_displayable', 10, 2);

    Also, be mindful with smart apostrophe/curly quotes . It doesn’t work if you use that, straight quote should be used '.

    Reference:
    https://mariushosting.com/how-to-upload-webp-files-on-wordpress/#:~:text=Log%20in%20to%20your%20WordPress,upload%20for%20webp%20image%20files.

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