• We have a custom block that lets people embed content from https://somedomain.com.
    The problem is that somedomain.com supports oEmbed (poorly, and we’d rather use our own block). Currently, if someone pastes a URL from somedomain.com into the block editor, it is automatically parsed into an Embed block. We’d like to stop that from happening, and encourage them to use our custom block instead.

    How can I tell WordPress to NOT use the available oEmbed for somedomain.com?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You could likely use the “oembed_result” filter. The oEmbed request will still be processed, but you can replace the returned content with whatever you want. You could add additional content or completely replace what was sent. The requested URL is passed to your callback, so altering the content only needs to be done for specific requests.

    Does not really “prevent” the oEmbed, but the ability to alter what the user sees is a plus.

    Thread Starter Jason LeMahieu (MadtownLems)

    (@madtownlems)

    Thanks for throwing an idea out there!

    I tried this, and just returning $url when the domain matches that one – but it has some problems.
    The biggest one is that, while it doesn’t actually USE the oEmbed response, it still wants to put it into an embed block. And fails when I try to publish ??

    add_filter( ‘oembed_result’, ‘ext_filter_oembed_result’ );

    function ext_filter_oembed_result( $data, $url, $args ) {

    ? ? if ( str_contains( $url, ‘somedomain.com’ ) ) {

            return $url;

        }

        return $data;

    }

    Moderator bcworkz

    (@bcworkz)

    Sorry, I’m at a loss. Apparently the oEmbed process changed with Gutenberg. The usual PHP tricks I knew about no longer work.

    It seems oEmbeds get processed through the REST API now. An API request returns a JSON encoded HTML document that gets embedded in a iframe. I’m unsure how to intercept that to do what you want. There ought to be a way, but it’s beyond my comprehension.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to Prevent oEmbed from one specific domain’ is closed to new replies.