Useful Code Snippets for the ShortPixel Image Optimizer

Published on October 15, 2020 by Sebastian Moran in MainWP Blog under Tips & Tricks
Heads up: This page may include affiliate links. Read the full disclaimer.

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_API_KEY', 'APIKEY');
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.

define('SHORTPIXEL_USE_DOUBLE_WEBP_EXTENSION', true);

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

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( 'cdn.shortpixel.ai/client/', 'cdn.shortpixel.ai/client2/', $HtmlIn );
}

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

Share

Manage Unlimited WordPress Sites from One Dashboard!

  • Privacy-first, Open Source, Self-hosted
  • Easy Client Management
  • 15+ & 30 + Premium Add-ons
  • Bulk Plugins & Themes Management
Get Pro Now

Categories

Recent Posts

Search MainWP.com

[searchwp_form id="1"]