3

I am using a modal to load post content via AJAX. Inside the post's template I am using wp_oembed_get() to embed different types of media (YouTube, Vimeo, Flickr, and Instagram). Everything is working, except for Instagram.

When I open a post that contains an Instagram embed, it loads fine. But if I close the modal and try to load another post, the embed does not work correctly. The photo/video within the embed does not load.

This is the page: http://staging.smuttynose.com/the-hopper

If you open one of the "Instagram Test" posts, close it, then load the other one, you will see what is happening.

I'm at the end of my rope in figuring this out!

  • I just ran into the same issue. Instagram has changed its embed code to include a js file which obviously does not run the content is loaded through Ajax. Did you find and solution for this? – Banago Mar 4 '15 at 9:01
  • Unfortunately I did not. I'd still be curious if anyone has a solution or alternative. Working with these social APIs is a pain in the butt. – Adam Walter Mar 4 '15 at 23:03
  • I figured it out - will post it as an separate answer. – Banago Mar 5 '15 at 13:47
3

Instagram has changed its embed code from being just an iframe to a bunch of HTML and a JS script. Very inelegant, but nothing we can do. This setup, of course, fails when called through AJAX since the JS file that's part of the HTML does not run. Thankfully there is another official way to make it work with AJAX in two steps:

  1. Include this scripts in your HMTL:

    <script src="//platform.instagram.com/en_US/embeds.js"></script>

  2. Runs this JS after you load the content with AJAX:

    if ( typeof window.instgrm !== 'undefined' ) { window.instgrm.Embeds.process(); }

What it does is, it looks for Instagram embeds and loads them. Best of luck!

  • 1
    Thank you! I've since abandoned what I was doing and got rid of the modal window to fix my problem, but this sounds like it would have worked! I'll mark as answered. – Adam Walter Mar 13 '15 at 14:27
  • 1
    You're a star this helped me fix my problem. – mary_berry Aug 18 '17 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.