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 name:flower.jpg pattern will let our plugin know that all JPG images that contain the word “flower” should not be compressed.

A pattern consists of a type:value pair. Type can be: name, path, size, regex-path or regex-name. Let’s see how you could use each of them.

For a Media Library item, the pattern will be matched against the name of the main image – not of its thumbnails – and will exclude the image together with all its thumbnails.

How to exclude files

Use the name type pattern to exclude particular images.

For example, if you wish to exclude “ logo.jpg” from optimization, then you will add name:logo.jpgin the Exclude patterns field.

A small change to the pattern will lead to a broader selection. For example, name:logo the pattern will select for exclusion all images – PNG/JPEG/GIF – that include the “logo” word in their name, as in “nicelogo.jpg”, “alllogos.png”, “logo.gif” and so on.

How to exclude folders

Use the path type pattern to exclude folders or subfolders.

All the path will be matched (useful for excluding certain subdirectories altogether). For these, you can also use regular expressions accepted by preg_match, but without “,” or “:”.

As an example, you can use path:/wp-content/uploads/2019/ to exclude this specific folder from optimization.

How to use the size pattern

Use size to exclude images bigger than a certain size.

The format for the size exclude is: minWidth-maxWidthxminHeight-maxHeight. For example, size:1000-1100x2000-2200. You can also exclude a specific size, such as size:1200x800

For the size type, which applies only to Media Library images, the main images (not thumbnails) that have the size in the specified range / specific size will be excluded.

The power of regular expressions

The regular expressions can help you set different exclude patterns. These are to be used with the types regex-name and regex-path. 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: regex-path:/\/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): regex-name:/(?i)flower/
  • All GIF images: regex-name:/\.gif$/
  • All images that are not GIF files: regex-name:/.*\.(?!gif$)[^.]+$/i
  • All PNG images that have a numeric prefix: regex-name:/[0-9]+[^\/]*\.(PNG|png)/

Regular Expression resources

Other rules to consider

These rules allow you to build more patterns.

  1. You can add multiple patterns separated by a comma. For example: name:example.jpg,path:themeimages/social
  2. A file will be excluded if it matches any of the patterns.
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us