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

Filters the cached oEmbed HTML.


Description

Top ↑

See also


Top ↑

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.

Top ↑

Source

File: wp-includes/class-wp-embed.php. View all references

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


Top ↑

Changelog

Changelog
Version Description
2.9.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Matt Radford

    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 2 content
    Contributed by swis

    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 3 content
    Contributed by Ryan Burnette

    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.