YouTube oEmbed and privacy-enhanced mode

At the moment WordPress only recognises youtube.com/watch, youtube.com/playlist and youtu.be. However there is wp_oembed_add_provider; try something like wp_oembed_add_provider( ‘#http://(www\.)?youtube-nocookie\.com/embed.*#i’, ‘http://www.youtube-nocookie.com/oembed’, true ); (untested sorry). You could even overwrite the existing providers to redirect to -nocookie and then use the video shortcode as normal. And you can do this with add_filter(‘oembed_providers’, … ); too if you’d … Read more

How to Replace YouTube Videos with a “Click to Play” Thumbnail?

Notes Solution for YouTube and Vimeo. Uses Featured Image or default thumbnail from video provider. If more than one oEmbed exists in the same page, using the Featured Image provoques duplicate “thumbs”. Post has to be updated before changes are seen. To do: <iframe> and <img> sizes, other oEmbeds. Sources of Inspiration oEmbed oEmbed, thumbnails … Read more

How to change default width parameter of embedded video in wordpress?

if you could make it to something like this: <div class=”videoWrapper”> <iframe width=”600″ height=”338″ src=”https://www.youtube.com/embed/f5CcOq8UzkI?feature=oembed” frameborder=”0″ allowfullscreen=””></iframe> </div> then responsive css for that would be like this: .videoWrapper { position: relative; padding-bottom: 56.25%; /* 16:9 */ padding-top: 25px; height: 0; } .videoWrapper iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } … Read more

How add class youtube and type/html to oembed code?

You can try this: add_filter( ’embed_oembed_html’, ‘custom_youtube_oembed’ ); function custom_youtube_oembed( $code ){ if( stripos( $code, ‘youtube.com’ ) !== FALSE && stripos( $code, ‘iframe’ ) !== FALSE ) $code = str_replace( ‘<iframe’, ‘<iframe class=”youtube-player” type=”text/html” ‘, $code ); return $code; } to target the YouTube oembed HTML output. When I embed this YouTube link (Kraftwerk) into … Read more

oEmbed, thumbnails and wordpress

Use the oembed_dataparse filter to modify the resulting HTML output by any given oembed call. Example: add_filter(‘oembed_dataparse’,’test’,10,3); function test($return, $data, $url) { if ($data->provider_name == ‘YouTube’) { return “<img src=”https://wordpress.stackexchange.com/questions/19500/{$data->thumbnail_url}”>”; } else return $return; } Then putting this in a post: Will give you a picture of Rick Astley instead of a flash video of … Read more

Apply the_content filter to a custom field with multiple values

All you need to do use apply_filters. foreach ($video as $vid) { echo ‘<li>’.apply_filters(‘the_content’,$vid).'</li>’; } It may be more efficient to concatenate a string and then run the filter on the whole thing. $lis=””; foreach ($video as $vid) { $lis .= ‘<li>’.$vid.'</li>’; } echo apply_filters(‘the_content’,$lis); I haven’t benchmarked the one versus the other but given … Read more

Featured Image of Video from oembed

I needed just this for a recent project, so here’s my plugin! The code should be self-explanatory, but if there are any questions ask away. <?php /** * Plugin Name: oEmbed Featured Image * Plugin URI: http://wordpress.stackexchange.com/q/70752/1685 * Description: Automatically set the featured image if an oEmbed-compatible embed is found in the post content. * … Read more

Get first video from the post (both embed and video shortcodes)

You could try mashing all the patterns together in one big regexp or and then doing a simple line by line parse of the content: function theme_oembed_videos() { global $post; if ( $post && $post->post_content ) { global $shortcode_tags; // Make a copy of global shortcode tags – we’ll temporarily overwrite it. $theme_shortcode_tags = $shortcode_tags; … Read more