How to flush the CDN cache for Autoptimize
Note: If you want to flush the cache for a specific image (not all), please refer to this article.
If you want to flush the whole ShortPixel's CDN cache for a WordPress website using Autoptimize with the image optimization option turned on, here's how you can do it:
- Install a code snippet plugin like this one.
- Go to Snippets > Add New.
- Give the snippet a name and copy-paste the code snippet below.
- Choose "Only run on site front-end". This will replace the CDN URL from
https://sp-ao.shortpixel.ai/client/
tohttps://sp-ao.shortpixel.ai/client2/
. The effect of this operation is to actually flush the whole cache.
add_filter('autoptimize_html_after_minify','change_shortpixel_client', 11, 1); function change_shortpixel_client( $HtmlIn ) { return str_replace( 'sp-ao.shortpixel.ai/client/', 'sp-ao.shortpixel.ai/client2/', $HtmlIn ); }