apply_filters( ’embed_oembed_html’, string|false $cache, string $url, array $attr, int $post_id )

Filters the cached oEmbed HTML.

Description

See also

Parameters

$cachestring|false
The cached HTML result, stored in post meta.
$urlstring
The attempted embed URL.
$attrarray
An array of shortcode attributes.
$post_idint
Post ID.

Source

return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $post_id );

Changelog

VersionDescription
2.9.0Introduced.

User Contributed Notes

  1. Skip to note 5 content

    Wrap oEmbed in a div. Useful for making video responsive, for example.

    add_filter( 'embed_oembed_html', 'wrap_oembed_html', 99, 4 );
    
    function wrap_oembed_html( $cached_html, $url, $attr, $post_id ) {
    	if ( false !== strpos( $url, "://youtube.com") || false !== strpos( $url, "://youtu.be" ) ) {
    		$cached_html = '<div class="responsive-video">' . $cached_html . '</div>';
    	}
    	return $cached_html;
    }
  2. Skip to note 6 content

    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.

  3. Skip to note 7 content

    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

You must log in before being able to contribute a note or feedback.