Problems using WP’s oembed function + Instagram + AJAX

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="https://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!

Leave a Comment