Trigger wp-embed via JavaScript to refresh iframe preview?

I'm running WordPress 6.0 and using the Block Editor to enable content editors to paste links that generate the embed/iframe preview, as described here.

I've noticed from time to time (i.e. erratically) the embed script doesn't seem to run, and the link remains as static text without converting into the iframe preview.

I'm also using Swup.js to handle page transitions throughout the site, and I'm wondering if wp-embed has a method of some kind that I can hook into to force the script to run and/or refresh the iframe preview?

If one exists, I could simply run the function by hooking into a Swup event, as described here. Thanks for any insight!

*Edit: I should add that the links in question are just URLs to other web sites- not social links, YouTube, etc.

Topic block-editor embed Wordpress javascript

Category Web


Unfortunately WP Embed isn't responsible for converting links into iframes.

The conversion of links and [embed] shortcodes into iframes is implemented by OEmbed and that happens via OEmbed APIs on the_content filter in PHP, not javascript.

It's much more likely that your transitioning to pages that use raw post content rather than processed/rendered content, e.g. templates that incorrectly use echo get_the_content(); or echo $post->post_content; to display their data, or use the raw content from the REST API. This is because those methods don't pass the content through the_content filter which converts links to OEmbeds, processes shortcodes, and renders server rendered blocks etc

WP Embed deals with iframes that already exist and helps with handling embed height. It already has DOM event listeners for when new DOMContent is loaded.

Triggering WP Embed is not your problem or the solution you are looking for, and your problem has nothing to do with WP Embed. You will need to look elsewhere to diagnose what is happening.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.