0

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.

0

1 Answer 1

1

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.

2
  • Wow, interesting- I had no idea that's how it works; I assumed a JS function was embedding the content. I am using a custom single.php template that echoes post content (I'm also using the Genesis framework), so apparently that's the root of the issue? Also, when you say "templates that incorrectly use echo get_the_post_content()" what is it exactly that's incorrect? What's most strange to me is how erratically the issue occurs- probably about 50% of the time (whether on initial page load or transitioning to the page from another.)
    – nickpish
    May 31 at 23:23
  • 1
    the problem is that it outputs raw unprocessed content, which means no shortcodes, no oembeds, no server rendered blocks etc. It has to go through the_content filter, aka echo apply_filters( 'the_content', get_the_content() ); which is just the_content();. The only other thing to note, is that OEmbeds don't always use iframes, sometimes they can use script tags, or other HTML, an iframe is just the most common method used as it's more reliable and secure
    – Tom J Nowell
    Jun 1 at 9:55

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.