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:
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
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
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
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 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-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:
- All images containing the word "flower" in the filename and ignoring case sensitivity (eg: will exclude files named flower, Flower, floWER, and so on):
- All GIF images:
- All PNG images that have a numeric prefix:
Regular Expression resources
Other rules to consider
These rules allow you to build more patterns.
- You can add multiple patterns separated by a comma. For example:
- A file will be excluded if it matches any of the patterns.