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 and activate a code snippet plugin such as this one.
- Navigate to Snippets > Add New.
- Give the snippet a name and copy-paste the code snippet below.
- Below the code, choose “Only run on site front-end“. This will replace all the instances of the CDN URL from
sp-ao.shortpixel.ai/client/
tosp-ao.shortpixel.ai/client2/
. The effect of this operation is to actually flush the CDN 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 ); }