Allow specific image URls to avoid going through Photon.
Parameters
- $image_url
string Image URL.
- $args
(array | string) Array of Photon arguments.
- $scheme
(string | null) Image scheme. Default to null.
- false
bool Should the image be returned as is, without going through Photon. Default to false.
Changelog
- Introduced in Jetpack 3.2.0
How to use this hook
Notes
You can use this filter to make sure some of the images on your site do not use Photon. In the example below, we’ll only use Photon for images belonging to our site, and make sure none of the images that are not hosted on our site get processed by Photon.
/**
* Only use Photon for images belonging to our site.
*
* @see https://wordpress.org/support/?p=8513006
*
* @param bool $skip Should Photon ignore that image.
* @param string $image_url Image URL.
* @param array|string $args Array of Photon arguments.
* @param string|null $scheme Image scheme. Default to null.
*/
function jeherve_photon_only_allow_local( $skip, $image_url, $args, $scheme ) {
// Get the site URL, without any protocol.
$site_url = preg_replace( '~^(?:f|ht)tps?://~i', '', get_site_url() );
/**
* If the image URL is from our site,
* return default value (false, unless another function overwrites).
* Otherwise, do not use Photon with it.
*/
if ( strpos( $image_url, $site_url ) ) {
return $skip;
} else {
return true;
}
}
add_filter( 'jetpack_photon_skip_for_url', 'jeherve_photon_only_allow_local', 9, 4 );