Skip to content

Instantly share code, notes, and snippets.

@jessestu
Last active November 4, 2019 18:07
Show Gist options
  • Save jessestu/2c95d1ab05d9a2750576541d87605a44 to your computer and use it in GitHub Desktop.
Save jessestu/2c95d1ab05d9a2750576541d87605a44 to your computer and use it in GitHub Desktop.
Add image optimization to your WordPress.com Business site!

Set up Jetpack Image CDN compression

This walkthrough sets up compression together with the Jetpack CDN plugin to create faster page loads.

By default, it sets the compression of images on the site to 80% quality to speed up load times. Adjust this by changing the 80 on line 3 of the code.

What to do:

  1. Install Code Snippets on your site: https://wordpress.com/plugins/code-snippets
  2. Activate code snippets either on that installation page or by going to My Site → WP-Admin → Plugins
  3. Go to My Site → WP-Admin → Snippets → Add New.
  4. Create a new snippet and give it a name that explains itself, such as: Jetpack Image CDN Compression
  5. Copy and paste the following PHP code into the Code text area:
add_filter('jetpack_photon_pre_args', 'jetpackme_custom_photon_compression' );
function jetpackme_custom_photon_compression( $args ) {
    $args['quality'] = 80;
    $args['strip'] = 'all';
    return $args;
}
  1. Choose "Run snippet everywhere."
  2. Save the changes.

Once you finish this process, the compression will begin working on your site the next time it loads. If you have any issues, please let our support know and we can help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment