0

If I paste a plain text link (non-hyperlinked) to a post on the same site (using Classic Editor) it converts the post's URL to an iFrame embed.

For example if my site is https://mysite.local and the URL to a product is https://mysite.local/product/test-product-1/, if I paste that product URL into the editor without converting it to a hyperlink, WordPress embeds the URL into an iFrame. I was under the impression WordPress would only do this with known embeddable sites, e.g. YouTube. Does anyone know why this is happening and how to prevent it?

Here is the embed HTML it converts the URL to:

<blockquote class="wp-embedded-content" data-secret="C6ebLBuv4n">
    <p>
        <a href="https://mysite.local/product/test-product-1/">Test Product 1</a>
    </p>
</blockquote>
<p>
    <iframe title="Test Product 1 - My Site" sandbox="allow-scripts" security="restricted" src="https://mysite.local/product/test-product-1/embed/#?secret=C6ebLBuv4n" width="500" height="282" data-secret="C6ebLBuv4n" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="wp-embedded-content"></iframe>
    <script>/*! This file is auto-generated */[REMOVED JAVASCRIPT]</script>
</p>

1 Answer 1

0

To prevent WordPress from automatically turning URLs into embeds, you can disable oEmbed for internal links. One way to do this is by adding a small function to your theme's functions.php file or a site-specific plugin. This function would stop WordPress from treating your own site's URLs as oEmbed sources.

Try this:

function disable_self_pingbacks( &$links ) {
    foreach ( $links as $l => $link ) {
            unset($links[$l]);
    }
}

add_action( 'pre_ping', 'disable_self_pingbacks' );
1
  • That's actually not working for me. The action is never fired. I modified the default twentytwentythree theme by adding add_action( 'pre_ping', function() { error_log( 'pre_ping' ); } ); into functions.php and it never outputs anything to the debug log.
    – Gavin
    Commented Nov 20, 2023 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.