Useful Code Snippets for the ShortPixel Image Optimizer

ShortPixel is a well-used plugin for image optimization on sites. The plugin includes a number of filters and constants.

You can hide your ShortPixel API key from the plugin’s settings by defining the API key in a constant in the sites wp-config.php file. Replace out the APIKEY with your actual API key for ShortPixel.

define('SHORTPIXEL_HIDE_API_KEY', true);

If you are using the ShortPixel plugin and service on sites which are hosted on FlyWheel then you might run into an error saying that flock (file locking) has been disabled for security reasons by using this constant in your sites wp-config.php file.

define("SHORTPIXEL_NOFLOCK", true);

If you are using ShortPixel with a site that uses LiteSpeed with the LiteSpeed Cache plugin then use can have LiteSpeed cache plugin service WebP files by using this constant in your sites wp-config.php file.


MainWP offers a solid extension to be able to save code snippets into all of your connected child sites.

Manage all your WordPress sites with the MainWP Dashboard

WordPress Management for Professionals

Are you ready to go Pro?

All MainWP Pro Extensions are available through one of our convenient bundled packages.

If you using ShortPixel CDN provided in the Autoptimize plugin setting and need to flush the CDN you can use this code snippet to do so.

add_filter('autoptimize_html_after_minify','change_shortpixel_client', 11, 1);
function change_shortpixel_client( $HtmlIn ) {
     return str_replace( '', '', $HtmlIn );

ShortPixel is a solid plugin and service for image optimization on your child site and hopefully, these constants and code snippets will help.

Looking for something?

Your Download Is Just One Click Away

…or just download the plugin.

By entering your email, you agree to our Terms of Service and Privacy Policy.