Filters the cached oEmbed HTML.
Description
See also
Parameters
$cache
string|false- The cached HTML result, stored in post meta.
$url
string- The attempted embed URL.
$attr
array- An array of shortcode attributes.
$post_id
int- Post ID.
Source
return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $post_id );
Changelog
Version | Description |
---|---|
2.9.0 | Introduced. |
Wrap oEmbed in a div. Useful for making video responsive, for example.
Note that https://developer.wordpress.org/reference/hooks/embed_oembed_html/#comment-1964 very incorrectly assumes that every oEmbed response contains a video, and even more incorrect raises the expectation that every oEmbed response has the same aspect-ratio.
Please never copy/paste the example as-is into your theme. Especially not when the theme is intended to be re-used/sold. It is killing oEmbed.
Props to Dave Romsey on StackExchange.
I wish I had known before I implemented code on this hook that JetPack overrides and doesn’t reimplement the filter. If you hook anything to this be sure you won’t be using JetPack or it won’t work. https://github.com/Automattic/jetpack/issues/1571
add_filter('video_embed_html', 'wrap_embed_html'); // Jetpack
To wrap oEmbed in a
div
it’s better to useoembed_dataparse
filter, cause it allows to get parameters of oEmbed, such as type, width and height.