Twitter's new-ish 'embedded tweets' feature is nice, but as far as I can tell the Twitter API's widgets.js can only render the embedded tweets at page load.
The doc page for embedded tweets is here: Embedded Tweets | Twitter Developers
It describes an oembed endpoint for "dynamically rendering" a tweet, but this only returns the bare HTML code that must still be transformed by widgets.js.
If I dynamically load some content via Ajax and insert it into the DOM, and that content includes the code for an embedded tweet, is there a way to get widgets.js to render that embedded tweet dynamically? A function or method call maybe?
It's possible to do by calling twttr.widgets.load(). Pass in an HTMLElement as the first argument to limit the search for uninitialized widgets to that element. For example:
twttr.widgets.load(document.getElementById("container"))
Source: https://developer.twitter.com/en/docs/twitter-for-websites/javascript-api/guides/scripting-loading-and-initialization
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With