Hey unicco,
The plugin uses the wp_upload_dir() function to locate the uploads folder and use it for the resized local images. Some CDNs solutions seem to change what is returned here and some don’t.
You can manually force the correct url for the images using this snippet added to your theme’s functions.php file:
function sb_change_for_cdn() {
?>
<script>
window.sb_instagram_js_options.resized_url = 'https://likehome.b-cdn.net/wp-content/uploads/sb-instagram-feed-images/';
</script>
<?php
}
add_action( 'wp_footer', 'sb_change_for_cdn', 99 );
let me know if you have more questions!
– Craig
This works great, but on pages where there’s no instagram feed, it gives this error
Uncaught TypeError: Cannot set property ‘resized_url’ of undefined
Ahh yes sorry about that! Let’s add a conditional here:
function sb_change_for_cdn() {
?>
<script>
if (typeof window.sb_instagram_js_options !== 'undefined') {
window.sb_instagram_js_options.resized_url = 'https://likehome.b-cdn.net/wp-content/uploads/sb-instagram-feed-images/';
}
</script>
<?php
}
add_action( 'wp_footer', 'sb_change_for_cdn', 99 );
Great!
Have a great rest of your week.
I kind of have a similar question. Will the code you added enable the images to be served via a CDN? I am using WP Rocket but with WP Engine’s CDN (don’t think it matters though).
Yes you would just want to adjust this line of code to match the URL of your CDN:
window.sb_instagram_js_options.resized_url = ‘https://likehome.b-cdn.net/wp-content/uploads/sb-instagram-feed-images/’;
Hopefully that helps!
– Craig
What is at end:
“add_action( ‘wp_footer’, ‘sb_change_for_cdn’, 99 );”?
Sorry I guess I’m not sure what you mean. Are you asking where you would add this code?
– Craig
No, I not understand what this code is it. 99 is what limit?
Hey @18tommyboy,
The 99 at the end is a mostly arbitrary priority number, where 99 basically means ‘load this last’. You can read more about the parameters here.
I hope this helps.
Best regards.