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

Filters the cached oEmbed HTML.


Top ↑

See also

Top ↑


$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 ↑


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

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

Top ↑


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, "://") || false !== strpos( $url, "://" ) ) {
    		$cached_html = '<div class="responsive-video">' . $cached_html . '</div>';
    	return $cached_html;
  2. Skip to note 2 content
    Contributed by swis

    Note that 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.

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