Exclude an image from being optimized when using Autoptimize

Autoptimize includes an image optimization feature, using ShortPixel's services. If, for whatever reason, you'd like to exclude one or more images from being optimized by Autoptimize, you can do so by following these instructions:

  1. Install a code snippet plugin like this one.
  2. Go to Snippets > Add New
  3. Give the snippet a name, add the code snippet below and choose to "Only run on site front-end".

Here's the snippet. Simply copy-paste it and replace the image filenames you see below (some-image.png, another-image.jpg) with the actual images you want to exclude. The list must be comma-separated and they can be an exact filename, a full path or part of the path.

add_filter('autoptimize_filter_imgopt_noptimize','imgopt_excl');
function imgopt_excl() {
return 'some-image.png, another-image.jpg';
}
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