Filter Youtube oembeds

I’m not sure how all of this code works exactly, but I was able to use it to remove the controls and title info by adding &showinfo=0&controls=0 to the youtube embeds on a website.

/**
* Add Custom Parameters to YouTube Embeds
*/
function namespace_oembed_youtube_no_title( $html, $url, $args ) {

// Only run this for YouTube embeds
if ( !strstr($url, ‘youtube.com’) )
return $html;

// Get embed URL
$url_string = parse_url($url, PHP_URL_QUERY);
parse_str($url_string, $id);

// Set default arguments
$defaults = array(
‘width’ => 480,
‘height’ => 385,
‘showinfo’ => false,
‘rel’ => false,
‘controls’ => 2,
‘autohide’ => true
);

// Merge args with defaults
$args = wp_parse_args( $args, $defaults );

// Define variables
extract( $args, EXTR_SKIP );

// Add custom parameter values to IFRAME
if ( isset($id[‘v’]) ) {
return ‘<div class=”post-video”><iframe width=”‘ . intval($width) . ‘” height=”‘ . intval($height) . ‘” src=”http://www.youtube.com/embed/’ . $id[‘v’] . ‘?rel=’ . intval($rel) . ‘&showinfo=’ . intval($showinfo) . ‘&controls=’ . $controls . ‘&autohide=’ . intval($autohide) . ‘” frameborder=”0″ allowfullscreen></iframe></div>’;
}

return $html;
}
add_filter(‘oembed_result’, ‘namespace_oembed_youtube_no_title’, 10, 3);

 

http://wordpress.stackexchange.com/questions/43198/any-way-to-use-a-custom-parameter-for-youtube-embed-without-using-an-iframe

 

Leave a Reply