View Categories

How to exclude images from being optimized?

You can exclude files or folders from optimization that match our accepted patterns by using the Exclude Patterns feature in the plugin settings (Settings > ShortPixel > Exclusions).

By patterns, we mean rules that our plugin understands. Don’t worry—ShortPixel Image Optimizer (SPIO) has a user-friendly interface that allows you to easily create your own exclusion patterns.

There are three types of exclusions: based on the file name (files), based on the file path (folders) or based on the file size. Each exclusion type can be applied to:

  • All versions of each image. This includes all thumbnails, the -scaled version and the original full-size image.
  • Only the thumbnails. In this case, the original and the -scaled version are not excluded.
  • Only Custom Media images. In this case the items from the Media Library are not excluded.
  • Only a selection of thumbnails of your choice.

How to exclude files #

Choose the Image Name exclusion type and enter part or all of the file name in the Value field.

For example, to exclude the “logo.jpg” image from optimization, enter logo.jpg in the Value field. Note that the value you enter is case-sensitive.

A small change to the pattern can result in a broader selection. For example, entering logo will exclude all images (PNG, JPEG, GIF) that contain “logo” in their name, such as “nicelogo.jpg”, “alllogos.png”, or “logo.gif”.

How to exclude folders #

Choose the Image Path exclusion type and enter part of the path you want to exclude in the Value field. Note that the value you enter is case-sensitive.

For example, entering 2022 in the Value field will exclude all images uploaded in 2022. This is because a default WordPress installation generates URLs like “https://mydomain.com/wp-content/uploads/2022/MM/myimage.jpg” (where “mydomain.com” is your domain, “2022” is the upload year, “MM” is the upload month, and “myimage.jpg” is the filename).

Note that, in the previous example, images with “2022” in the file name will also be excluded since it is part of the path. To exclude only images uploaded in 2022, enter /2022/ instead.

How to exclude file sizes #

Choose the Image Size exclusion type if you’d like to exclude all images and thumbnails within the specified size range. You can also specify an exact size by enabling the Exact sizes option.

The following example excludes all images smaller than 1024px wide from optimization.

The power of regular expressions #

Regular expressions can help you set more advanced exclude patterns. These can be used with the Image Name or Image Path types. A regular expression must be enclosed between slashes (/ /), and special characters should be escaped by adding a backslash in front of them. Here are a couple of examples that demonstrate their power:

  • All images from 2016: /\/2016\//
  • All images containing the word “flower” in the filename and ignoring case sensitivity (eg: will exclude files named “flower”, “Flower”, “floWER”, and so on): /(?i)flower/
  • All GIF images: /\.gif$/
  • All images that are not GIF files: /.*\.(?!gif$)[^.]+$/i
  • All PNG images that have a numeric prefix: /[0-9]+[^/]*\.(PNG|png)/

Regular Expression resources #