View Categories

How to exclude images from being optimized?

You can exclude files or folders from optimization that can be identified with our accepted patterns, by using the Exclude patterns feature in the plugin settings (Settings > ShortPixel > Advanced).

By patterns, we mean some rules that our plugin understands. For example, the pattern name:flower.jpg lets our plugin know that all JPG images containing the word “flower” should not be compressed. But don’t worry, ShortPixel Image Optimizer (SPIO) has a user-friendly interface that allows you to easily create your own exclusion patterns without having to write those difficult 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 image in full size.
  • 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 Name exclusion type and enter part or all of the file name in the Value field.

For example, if you want to exclude “logo.jpg” from optimization, you should enter “logo.jpg” in the Value field. Please note that the value you enter is case-sensitive.

A small change to the pattern will result in a wider selection. For example, “logo” will select all images – PNG/JPEG/GIF – for exclusion that contain the word “logo” in their name, such as “nicelogo.jpg”, “alllogos.png” or “logo.gif”.

How to exclude folders #

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

For example, if you enter “2022” in the Value field, all images uploaded in 2022 will be excluded.

Note that according to the previous example, images containing 2022 in the file name will also be excluded (as this is also part of the path). So if you only want to exclude images uploaded in 2022, enter “/2022/” instead.

How to exclude file sizes #

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

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

The power of regular expressions #

The regular expressions can help you set different exclude patterns. These are to be used with the Name or Path types. A regular expression must be contained between slashes (/ ) and special characters should be escaped by adding in front of them. Here are just a couple of examples that will show 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 #