Load Smash Balloon Instagram Feed Images Through a CDN

Quick Summary
- Override resized_url in the plugin's sb_instagram_js_options object so Smash Balloon feed images load through your CDN.
- The snippet prints the override on wp_footer at priority 99, after the plugin's settings; Statically no longer serves other sites' files, so use your own CDN's URL.
- Pages without the plugin's options object get a JavaScript error, so check that it exists or add the script only where feeds appear.
The Smash Balloon Instagram Feed plugin keeps resized copies of feed images in wp-content/uploads/sb-instagram-feed-images/ on your server. The plugin’s JavaScript reads the address of that folder from its sb_instagram_js_options object. This snippet overrides that address so the feed images load through a CDN. An earlier version of this snippet used a Statically address, but Statically no longer serves files from other websites, so the example now uses a placeholder: put your own CDN’s address in its place.
Add it to your child theme’s functions.php file. The Instagram Feed plugin must be active.
// INSTAGRAM FEED CDN ISSUE FIX
function sb_change_for_cdn() {
?>
<script>
if ( window.sb_instagram_js_options ) {
window.sb_instagram_js_options.resized_url = 'https://cdn.example.com/wp-content/uploads/sb-instagram-feed-images/';
}
</script>
<?php
}
add_action( 'wp_footer', 'sb_change_for_cdn', 99 );How it works
wp_footerprints the small script at the bottom of every page. Priority99puts it late, after the plugin’s own settings have been printed.- The script sets
resized_url, the base URL the plugin uses for resized images, to a CDN address. - Replace
https://cdn.example.com/wp-content/uploads/with the URL where your CDN serves youruploadsfolder, and keepsb-instagram-feed-images/at the end.
The if check skips pages where the plugin hasn’t printed sb_instagram_js_options, so pages without a feed don’t get a JavaScript error. After the change, clear your cache and use the Network tab in your browser’s developer tools to confirm the feed images come from the CDN.
For image loading and CDN setup across the whole site, see my WordPress SEO and performance services.
Related articles
- setting browser cache times for images: for the files your own server still serves
- deferring JavaScript files in WordPress: another speed fix added from functions.php
