After the introduction of the embeds feature in WordPress 4.4 there have been a few significant changes in 4.5 to make embeds more robust and easier to customize.
Embed Code Adjustments
There were two minor changes to the <iframe>
embed code:
- The iframe’s
title
attribute has been adjusted to better describe its content for improved accessibility. - The iframe is now hidden using a different technique to prevent images from not being displayed properly in Firefox, working around a known bug in that browser.
Discovery Improvements
Ticket: #35979
Since WordPress 4.4, oEmbed discovery has been turned on by default. Using auto discovery, WordPress tries to find embeddable content when a URL is pasted on a new line in the editor. [36880] prevents timeouts from happening when requesting the URL by limiting the response size to 150KB.
Embedding Static Front Pages
Ticket: #34971
Previously, embedding a static front page was not possible due to not having an /embed/
endpoint. Now embed
is a reserved slug that can’t be used for new pages/posts. When https://example.com/foo/embed/
is an existing page, embeds fall back to https://example.com/foo/?embed=true
.
Embed Template Changes
Tickets: #35322, #35630, #34561
- The site icon in the embed template used to fall back to an image located inside
/wp-admin/
. This was problematic when the directory is not accessible to the public. That image is now loaded from inside/wp-includes/
. - Thanks to an adjusted click event handler, links inside the iframe now work even when they’re inserted dynamically after the page load.
- By far the biggest changes affect the way the embed template is loaded
. Most notably, the old
wp-includes/embed-template.php
file has been deprecated and split into five new template parts that can be individually overridden by themes:- embed.php
- embed-404.php
- embed-content.php
- header-embed.php
- footer-embed.php
The five new template parts live in /wp-includes/theme-compat/
and allow core to gracefully fall back should themes prefer not to override any or all of them.
Previously, the embed template could only be changed using the embed_template
filter. This filter can now be leveraged directly within the template hierarchy via the already-existing {$type}_template
filter (where $type
equals “embed”).
See get_query_template()
and locate_template()
for more information.
See [36693] for the relevant changeset.
Embeds in the Template Hierarchy
Ticket: #34278
In addition to the new base embed.php
template and related template parts, themes can now implement embed templates for specific post types and post formats within the confines of the template hierarchy. The embeds template cascade looks like this:
embed-{post-type}-{post_format}.php
embed-{post-type}.php
embed.php
wp-includes/theme-compat/embed.php
Note that this is the first time direct theme-compat
inheritance has been integrated with the template hierarchy. This approach allows core to provide basic, yet standardized templates and template parts for handling post embeds.
To leverage the core embed template parts, simply use standard get_template_part()
calls within your themes. The template hierarchy will do the rest.
For example:
- If the theme is leveraging its own version of
embed.php
template, it would likely call template parts directly, e.g.get_template_part( 'embed', 'content' );
- If the theme is relying on the core embed template parts – i.e. not providing its own
embed-content.php
file – the template hierarchy would fall back to usingwp-includes/theme-compat/embed-content.php
, and so on.
See [36876] for the relevant changeset.
Note:
For more information on extending embeds within the scope of the template hierarchy, check out the new Embeds section in the Template Hierarchy reference in the Theme Developer handbook.
Embeds Changes in WordPress 4.5 by Pascal Birchler was originally posted at https://make.wordpress.org/core/2016/03/11/embeds-changes-in-wordpress-4-5/
No comments:
Post a Comment