WordPress has been operating as an oEmbed consumer for quite some time now, allowing users to easily embed content from other sites. Starting with version 4.4, WordPress becomes an oEmbed provider as well, allowing any oEmbed consumer to embed posts from WordPress sites.
Here’s how that looks:
In order to achieve this, WordPress’ oEmbed consumer code has been enhanced to work with any site that provides oEmbed data (as long as it matches some strict security rules). For security, embeds appear within a sandboxed iframe – the iframe content is a template that can be styled or replaced entirely by the theme on the provider site.
Related ticket: #32522
What That Means for Developers
First of all, this new feature means that any post (or basically any public post type) will now be embeddable. If you’re using pretty permalinks, the embeddable content will be available at example.com/your-post/embed/.
If you’re a developer, make sure you do not add an
embed rewrite endpoint yourself!
Functions and Hooks
Here are the four most useful functions related to embeds:
get_post_embed_url() — Retrieves the URL to embed a specific post in an iframe, e.g.
get_post_embed_html() — Retrieves the full embed code for a specific post.
get_oembed_endpoint_url() — Retrieves the oEmbed endpoint URL for a given permalink, e.g.
https://make.wordpress.org/core/?oembed=true&url=<url>. This is used to add the oEmbed discovery links to the HTML <head> for single posts.
get_oembed_response_data() — Retrieves the oEmbed response data for a given post, according to the oEmbed specification.
Of course the return values of these functions are all filterable, making it easy for you to customize this new feature.
Customizing The Output
The embed template mentioned earlier can be customized similarly to any theme template file. Use
embed_footer to add custom code in the beginning and the end of the template.
Note that an
X-WP-embed:true header will be sent when that template is used, so you can easily target embedded posts in your application.
We’re currently tweaking the embeds functionality to sort out the last few bugs. Here’s a short list of tickets that are being worked on and their purposes:
#34204 — Improved support for IE7+. This will also introduce a
#34451 — Improved support for embedding posts on non-WordPress sites
#34278 — Add support for embeds in the theme template hierarchy, allowing you to override the template easily in your theme.
#34207 — Leverage the REST API structure for the oEmbed endpoint.
#34462 — Add a
<blockquote> fallback for the iframe.
Disabling The Feature
Don’t like these enhanced embeds in WordPress 4.4? You can easily disable the feature using the Disable Embeds plugin if you really want to.