Support » Plugin: Smash Balloon Social Photo Feed » Loading images through CDN

  • Resolved unicco

    (@unicco)


    Hi. Seems like my images aren’t being loaded through my CDN service, which hurts my SEO values on various SEO-checking services like for instance Google Insight.

    Check out: https://imgbb.com/

    I’ve setup rewrites on all images using WP Rocket CDN service.

    Is this a bug or am I just missing out some configurations?

    The page I need help with: [log in to see the link]

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Craig at Smash Balloon

    (@craig-at-smash-balloon)

    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

    Plugin Author Craig at Smash Balloon

    (@craig-at-smash-balloon)

    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 );

    perfect. Thank you

    Plugin Author Craig at Smash Balloon

    (@craig-at-smash-balloon)

    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).

    Plugin Author Craig at Smash Balloon

    (@craig-at-smash-balloon)

    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/&#8217;;

    Hopefully that helps!

    – Craig

    18TommyBoy

    (@18tommyboy)

    What is at end:
    “add_action( ‘wp_footer’, ‘sb_change_for_cdn’, 99 );”?

    Plugin Author Craig at Smash Balloon

    (@craig-at-smash-balloon)

    Sorry I guess I’m not sure what you mean. Are you asking where you would add this code?

    – Craig

    18TommyBoy

    (@18tommyboy)

    No, I not understand what this code is it. 99 is what limit?

    Plugin Support Smash Balloon Joel

    (@joelsmashballoon)

    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.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Loading images through CDN’ is closed to new replies.