WordPress oEmbed W3C Validation

The class-oembed.php file reveals some of the available filters regarding the oEmbeds. We can use the oembed_result or oembed_dataparse filters to modify the HTML fetched from Vimeo before it’s cached in the post meta. Here’s an example for the latter: add_filter( ‘oembed_dataparse’, function( $return, $data, $url ) { // Target only Vimeo: if( is_object( $data … Read more

Set wmode attribute to transparent for the embed shortcode to make drop-down menu hover over YouTube embed in Internet Explorer

You can filter the HTML output for oEmbed with oembed_result. Now test the HTTP host of the URL for www.youtube.com and add the parameter. The oEmbed result is cached in a post meta field to avoid too many requests. To update old posts I have added an activation helper that clears those cached content for … Read more

Add wrapper to only youtube videos via embed_oembed_html filter function

$url will contain the full URL to the embed source. E.g.: https://www.youtube.com/watch?v=_UmOY6ek_Y4, so you have to search within $url to see if the provider’s name appears: add_filter( ’embed_oembed_html’, ‘wpse_embed_oembed_html’, 99, 4 ); function wpse_embed_oembed_html( $cache, $url, $attr, $post_ID ) { $classes = array(); // Add these classes to all embeds. $classes_all = array( ‘responsive-container’, ); … Read more

Extract the first oembed url inserted on the content of a post

I assume that you’re only interested in the first URL that actually succeeds at discovering actual oembed data. The oembed system processes all links it finds, but not every link will have oembed going for it, obviously. The filter you’ll want to use is embed_oembed_html and it gets the HTML cached by oembed, the url, … Read more

Changing Oembed max width based type of page

Using the following in your functions.php file should do the trick: /** * Configure default oEmbed video sizes */ function base_oembed_defaults($embed_size) { if( is_single() ) { $embed_size[‘width’] = 580; $embed_size[‘height’] = 435; } return $embed_size; } add_filter(’embed_defaults’, ‘base_oembed_defaults’); Add as many WordPress conditional statements as you like to match the desired aspect ratio for each … Read more

Fallback for oEmbed content

Probably impractical. When you do not control the content you can not know if it will be embedable at the time of viewing. Easiest example of why it might be hard in the context of youtube/vimeo is videos that can become restricted, either private or geo restricted. In that case the content is still embedable … Read more

Heartbeat API oEmbed

The problem: The reason why this isn’t working, is this part of the WP_Embed::shortcode() method: if( $post_ID ) { …. cut … // Use oEmbed to get the HTML $html = wp_oembed_get( $url, $attr ); … cut … } When trying to autoembed with the Heartbeat API the $post_ID is null, so wp_oembed_get() is never … Read more