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:
Feature Plugin Merge Proposal: oEmbed
Related ticket Created for both bug reports and feature development on the bug tracker.: #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 In WordPress theme and development, hooks are functions that can be applied to an action or a Filter in WordPress. Actions are functions performed when a certain event occurs in WordPress. Filters allow you to modify certain functions. Arguments used to hook both filters and actions look the same.
Here are the four most useful functions related to embeds:
get_post_embed_url() — Retrieves the URL A specific web address of a website or web page on the Internet, such as a website’s URL www.wordpress.org 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 HyperText Markup Language. The semantic scripting language primarily used for outputting content in web browsers. <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 The header of your site is typically the first thing people will experience. The masthead or header art located across the top of your page is part of the look and feel of your website. It can influence a visitor’s opinion about your content and you/ your organization’s brand. It may also look different on different screen sizes. 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 The REST API is an acronym for the RESTful Application Program Interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data. It is how the front end of an application (think “phone app” or “website”) can communicate with the data store (think “database” or “file system”) https://developer.wordpress.org/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 A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory https://wordpress.org/plugins/ or can be cost-based plugin from a third-party if you really want to.