How to exclude images from optimization in the ShortPixel Adaptive Images plugin

In some circumstances you need to exclude from optimization some images, either due to some incompatibility with another plugin, or just because you need the original images there. ShortPixel Adaptive Images offers two ways to exclude images:

  1. Based on CSS selectors
  2. Based on URL

For the CSS selector method, you need to identify the element using Developer Tools's Inspector arrow: selecti it and click on the image, then inspect the markup of the page for that image. In the example image below, you will notice that the image has a class called attachment_thumb_big.

This image and all images having the same class can be excluded with this rule: img.attachment_thumb_big. You can also exclude images based on the id attribute: img#id_of_the_image


For the URL exclusion method, you can either input a part of the URL:

  • `path:/my/path/`
  • path:www.someothersite.com
  • path:logo.jpg

or use a regular expression. For example, the next one excludes all GIF images from optimization:

  • regex:/.*\.gif$/i  - this one excludes all GIF images from optimization
  • regex://\/\/([^\/]*\.|)gravatar.com\//  - this one excludes all the images from subdomains of gravatar.com

The first part, regex:, is not part of the regular expression but is flagging the next part as regular expression. For more info about regular expression, please read this howto. You can validate your regular expressions here: regex101.com

You can define multiple exclusions, each on a separate line.Please keep them as few as possible though, as a huge number of them could impact site performance.

Please also note that the plugin will silently ignore the malformed exclusions,


Still need help? Contact Us Contact Us