• Resolved GreenDragon

    (@hliltd)


    I am having problems with the webp plugin as I use emails with images sent from wordpress website and the email clien cannot show the images in the emails.

    I need to be able to “Exclude” an image from webp conversion.

    Can someone please explain how to and where to create a filter to do this.

    many thanks

    Glyn

    • This topic was modified 4 years, 8 months ago by GreenDragon.
    • This topic was modified 4 years, 8 months ago by GreenDragon. Reason: update title and content
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter GreenDragon

    (@hliltd)

    Hi can you please assist in excluding images from webp plugin

    Thread Starter GreenDragon

    (@hliltd)

    The image I need to exclude from webp conversion is logo.png
    I have now renamed it to logo-email.png

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hi @hliltd,

    Thank you for your message.

    In this arrangement, I suggest that you add suffix to all images that you would like to exclude from converting. For example, if the image is named my-image-01.jpg, before uploading the file to the media library, change its name to my-image-01-email.jpg.

    When you use the -email suffix, you can use the following filter to exclude files from converting to WebP (you can use a different suffix, but remember to change it in the filter code):

    add_filter('webpc_attachment_paths', function($paths) {
      $suffix = '-email';
      foreach ($paths as $index => $path) {
        if (!preg_match('/(.*?)' . $suffix . '((-(.*))?)\.(jpe?g|png|gif)/', basename($path))) continue;
        unset($paths[$index]);
      }
      return $paths;
    });

    By adding a filter, you are not editing the plugin code because these changes were removed during the upgrade. Please add this code to the functions.php file (at the bottom) in your theme directory, eg.:
    /wp-content/themes/my-theme/functions.php

    Then try to upload the file containing suffix -email to the media library. It will only be available in its original format and will not be converted to WebP.

    Thread Starter GreenDragon

    (@hliltd)

    Hi @mateuszgbiorczyk,

    Many thanks for the fast response and resolution to the issue.
    I have made the requested code changes and am now testing.

    I will post results shortly.

    Glyn

    Thread Starter GreenDragon

    (@hliltd)

    testing complete.

    This worked perfectly.

    Many thanks for such great support

    Glyn

    • This reply was modified 4 years, 8 months ago by GreenDragon.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to exclude selected images from converting to WebP’ is closed to new replies.