PHP snippet · Performance

Disable oEmbed discovery and the embed script

Stops your site advertising itself as embeddable and drops wp-embed.min.js from every page. Pasting YouTube and Vimeo links still works.

About this php snippet

WordPress ships an oEmbed layer so that other sites can embed your posts, and it loads a script on every page to resize those embeds. Most sites never use either half.

Note what this does not touch. Pasting a YouTube or Vimeo URL into a post still turns into a player, exactly as before. This only turns off your site advertising itself as embeddable, and the front-end script that goes with it.

What it does

  • Removes the oEmbed discovery links from the page head
  • Removes the oEmbed host JavaScript and dequeues wp-embed.min.js
  • Unregisters the oEmbed REST route
  • Stops WordPress fetching an unknown URL just to sniff it for oEmbed support

Good to know

  • Known providers such as YouTube, Vimeo, and X are unaffected, because they are matched from a built-in list rather than by fetching the page
  • Core registers the discovery links twice, at two different priorities, so the one-line version of this snippet you find on most blogs removes one copy and leaves the other still printing. This removes both, which is why it actually works.
  • The one reason to leave it alone is if other WordPress sites embed your posts and you want them to keep finding the endpoint
  • A rare self-hosted provider that relied on discovery will no longer auto-embed. Paste an iframe for those.

More php snippets

Your EMCP guide

Answers from our docs

YOUR CHAT, YOUR CHOICE

Before we chat

MSR Builds processes your question and up to four recent messages on our server to answer from the EMCP docs. AI is optional and needs your separate permission.

The chat is kept in this page's memory, not saved as a conversation in our database or browser storage. Our hosting and security services process connection information, such as your IP address, to prevent abuse.

Cloudflare Turnstile checks your browser and connection to prevent automated abuse when you send a question. No login is required.

Please leave out personal, sensitive or confidential information, passwords and API keys.

You can withdraw consent and clear this page's chat at any time. This cannot undo a request already sent or erase provider/security records.

Chat privacy, retention & your rights ↗ · Privacy contact

Starting chat consents to this processing. You can browse our docs without using the chat.