Jetpack

Skip an Image with Photon

Once you activate the Photon module, it will automatically cache and serve all images you’ve added to your posts and pages that have been uploaded to your site.

You can exclude a specific image or an entire page from Photon easily.

To exclude an entire post or page from using Photon, you can modify this snippet to fit your needs and add it to your theme’s functions.php or a core functionality plugin:

function no_photon_by_page() {
  if ( is_page( 2 ) ) {
    add_filter( 'jetpack_photon_skip_image', '__return_true');
  }
}

add_action('wp', 'no_photon_by_page');

In this example, Photon won’t be used on the page with the ID of 2, but you can use any of the WordPress Conditional Functions.

If you’d like to exclude an image from being cached and served by Photon, you can add the following code to your theme’s functions.php file:

function my_photon_exception( $val, $src, $tag ) {
        if ( $src == 'YOUR_IMAGE_URL' ) {
                return true;
        }
        return $val;
}
add_filter( 'jetpack_photon_skip_image', 'my_photon_exception', 10, 3 );

If you’d like to disable Photon in other specific situations instead, you can check this tutorial.

This entry was posted in Code snippets, Tips & Tricks and tagged . Bookmark the permalink.
Follow

Get every new post delivered to your Inbox.

Join 63,480 other followers