Allow specific images to be skipped by Photon.
Parameters
- $src
string Image URL.
- $tag
(string | array | null) Image Tag (Image HTML output) or array of image details for srcset.
- false
bool false Should Photon ignore this image. Default to false.
Changelog
- Introduced in Jetpack 2.0.3
How to use this hook
Notes
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 );
To exclude images from a specific domain, you can use the following code:
function htdat_photon_exception_for_domain ( $val, $src, $tag ) {
$parse = parse_url( $src );
$img_domain = $parse[ 'host' ];
// specify the domain you want to exclude here. Note: www and non-www are different
if ( $img_domain == 'domain.com' ) {
return true;
}
return $val;
}
add_filter( 'jetpack_photon_skip_image', 'htdat_photon_exception_for_domain', 10, 3 );