<?php
/*
Plugin Name: YouTube wmode adjuster
Description: This plugin will modify the YouTube oEmbed output and add some parameters.
Author: Jan Dembowski
Author URI: http://blog.dembowski.net/
Version: 0.1
*/
/*
From http://wordpress.org/support/topic/help-adding-wmodetransparent-to-oembeds
Example:
<iframe width="625" height="352" src="http://www.youtube.com/embed/MCWJUSulnro?feature=oembed" frameborder="0" allowfullscreen></iframe>
Replace ?feature=oembed with ?wmode=transparent and add wmode="Opaque" to the end of the <iframe ...>
<iframe width="625" height="352" src="http://www.youtube.com/embed/MCWJUSulnro?wmode=transparent" frameborder="0" allowfullscreen wmode="Opaque"></iframe>
*/
add_filter( 'the_content' , 'mh_youtube_wmode' , 15 );
add_filter('bp_get_activity_content_body','mh_youtube_wmode');
function mh_youtube_wmode( $content ) {
// Regex to find all <ifram ... > YouTube tags
$mh_youtube_regex = "/\<iframe .*youtube\.com.*><\/iframe>/";
// Populate the results into an array
preg_match_all( $mh_youtube_regex , $content, $mh_matches );
// If we get any hits then put the update the results
if ( $mh_matches ) {;
for ( $mh_count = 0; $mh_count < count( $mh_matches[0] ); $mh_count++ )
{
// Old YouTube iframe
$mh_old = $mh_matches[0][$mh_count];
$mh_new = str_replace( "?feature=oembed" , "?wmode=transparent" , $mh_old );
$mh_new = preg_replace( '/\><\/iframe>$/' , ' wmode="Opaque"></iframe>' , $mh_new );
// make the substitution
$content = str_replace( $mh_old, $mh_new , $content );
}
}
return $content;
}