Top of page

Add Jetpack Image CDN To Advanced Custom Fields Image Fields

Varmapublished on January 23, 2020 & last updated on September 14, 2020

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 15% discount on Jetpack Personal, Premium & Professional Plan

Get flat 15 per cent discount on Jetpack Personal, Jetpack Premium and Jetpack Professional plans which offers advanced marketing tools, on-demand backup and scanning, priority support and more.

Flat 15% Coupon
NEWSITE2020 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...