Top of page

Add Jetpack Image CDN To Advanced Custom Fields Image Fields

Varmapublished on January 23, 2020 & last updated on January 18, 2022

To maximize website performance in a WordPress site we should serve images and other static assets via a content delivery network (CDN). Jetpack plugin, the ultimate toolkit for WordPress offers just that for free. Using its image CDN (formerly Jetpack Photon) you could host all your images freely on the blazing-fast WordPress infrastructure. Thus easing load on your server and serving images faster to your site visitors.

JetPack Image CDN by default does not rewrite images uploaded with Advanced Custom Fields. But you could use the Photon API to transform images using GET query arguments.

Add Jetpack Photon CDN filter to your ACF image field (make sure you have the ACF image field set to return images are URL).

<?php echo apply_filters( 'jetpack_photon_url', get_field('image_field') ); ?>

If you' have already built out a WordPress theme with ACF image fields and it's hard to change each one of them (in numerous theme files) with the above snippet, then you could try the below snippet (add it to your theme functions.php file).

function acf_image_photon_urls($url, $post_id) {
    return str_replace('', '', $url);
add_filter('acf/format_value/type=image', 'acf_image_photon_urls', 2);

The above snippet replaces all images in the ACF image field type to Jetpack image CDN URL based URLs. You could also replace the Jetpack Photon CDN URL in the above code to any of these -, or CDN domains.

In Jetpack

Flat 40% OFF on WordPress Jetpack plans

Get flat 40 per cent discount on WordPress Jetpack automated real-time backups. security scan and other premium plans. Jetpack Security pack provides easy-to-use, comprehensive WordPress site security including automated backups, malware scanning, and spam protection.

40% OFF Coupon
JETBLACK CopyGet this deal

In Perfmatters WordPress Performance Plugin

Flat 10% OFF on Perfmatters WordPress Performance Plugin

Get flat 10 per cent discount on Perfmatters WordPress Performance Plugin.

10% OFF Coupon
PERFMATTERS CopyGet this deal

Related Articles

Fetching coffee...