embed_oembed_htmlfilter-hookWP 2.9.0

Allows you to change cached oEmbed HTML when it is displayed.

Read oEmbed in WordPress to learn what oEmbed is.

WP_Embed::shortcode() is responsible for creating the metadata.

Usage

add_filter( 'embed_oembed_html', 'wp_kama_embed_oembed_html_filter', 10, 4 );

/**
 * Function for `embed_oembed_html` filter-hook.
 * 
 * @param string $cache   The cached HTML result, stored in post meta.
 * @param string $url     The attempted embed URL.
 * @param array  $attr    An array of shortcode attributes.
 * @param int    $post_id Post ID.
 *
 * @return string
 */
function wp_kama_embed_oembed_html_filter( $cache, $url, $attr, $post_id ){

	// filter...
	return $cache;
}
$cache(string/false)
The cached response HTML stored in the post metadata.
$url(string)
The URL of the requested entity (a YouTube video, etc.).
$attr(array)
An array of shortcode attributes (presets).
$post_ID(integer)
The post ID.

Examples

#1 Add a wrapper to all oEmbed content

add_filter( 'embed_oembed_html', 'add_my_wrapper_all_oembed' );

function add_my_wrapper_all_oembed( $cache ) {
	return sprintf( '<div class="my-class-wrapper">%s</div>', $cache );
}

#2 Add a wrapper only to the YouTube player

add_filter( 'embed_oembed_html', 'add_youtube_wrap_oembed', 10, 2 );

function add_youtube_wrap_oembed( $cached, $url ) {
	if ( false !== strpos( $url, "://youtube.com" ) || false !== strpos( $url, "://youtu.be" ) ) {
		return sprintf( '<div class="youtube-wrapper">%s</div>', $cached );
	}

	return $cached;
}

Changelog

Since 2.9.0 Introduced.

Where the hook is called

WP_Embed::shortcode()
embed_oembed_html
wp-includes/class-wp-embed.php 291
return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $post_id );
wp-includes/class-wp-embed.php 374
return apply_filters( 'embed_oembed_html', $html, $url, $attr, $post_id );

Where the hook is used in WordPress

wp-includes/default-filters.php 738
add_filter( 'embed_oembed_html', 'wp_maybe_enqueue_oembed_host_js' );