How to flush the CDN cache for Autoptimize

Note: If all you want to do is flush from cache only a single image (not all), please click here.

If you need to flush ShortPixel's CDN cache for a WordPress website using Autoptimize with the image optimization option turned on, here's how you can do it:

  1. Install a code snippet plugin like this one.
  2. Go to Snippets > Add New.
  3. Give the snippet a name and add the code snippet below and choose to "Only run on site front-end". This will replace the CDN URL from to and the effect of this is to actually flush the whole cache.

Here's the snippet. Simply copy-paste it:

add_filter('autoptimize_html_after_minify','change_shortpixel_client', 11, 1);
function change_shortpixel_client( $HtmlIn ) {
    return str_replace( '', '', $HtmlIn );
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