Instagram embeds not working when adding embeds dynamically

Working on a blog that loads posts on an infinite scroller. Each blog post may or may not have Instagram embeds. I'm finding that the first one that shows on the page will get processed (regardless if it's in the initial page markup, or dynamically added), the following ones will not. Here is a simple JS Bin that illustrates the problem:,js,output

The first Instagram embed is in the initial page markup. Another Instagram embed is added after page load, after 4 seconds. The second embed add does not get processed.

Any ideas why? It seems the Instagram embed script will only run once. Any way I can force it to refresh?

Thanks, Matt



The embed.js script that comes with Instagram's embed code has a process function you can call.


Just use that whenever your dynamic content loads.


In your app.js create a directive for adding script element:

.directive('externalscript', function() {
   var injectScript = function(element) {
    var instagramScript = angular.element(document.createElement('script'));
    instagramScript.attr('async defer');
    instagramScript.attr('charset', 'utf-8');
    instagramScript.attr('src', '');
    instagramScript.attr('onload', 'window.instgrm.Embeds.process()');
    var twitterScript = angular.element(document.createElement('script'));
    twitterScript.attr('async defer');
    twitterScript.attr('charset', 'utf-8');
    twitterScript.attr('src', '');

  return {
      link: function(scope, element) {

and then in your html view call:

<div externalscript></div>

Inserting this into header and footer area worked for me in WordPress blog.

<script async="" defer="defer" src="//"></script>


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.