Advertisement
jan_dembowski

youtube-wmode.txt

Jan 26th, 2013
980
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: YouTube wmode adjuster
  4. Description: This plugin will modify the YouTube oEmbed output and add some parameters.
  5. Author: Jan Dembowski
  6. Author URI: http://blog.dembowski.net/
  7. Version: 0.1
  8. */
  9.  
  10. /*
  11. From http://wordpress.org/support/topic/help-adding-wmodetransparent-to-oembeds
  12.  
  13. Example:
  14. <iframe width="625" height="352" src="http://www.youtube.com/embed/MCWJUSulnro?feature=oembed" frameborder="0" allowfullscreen></iframe>
  15.  
  16. Replace ?feature=oembed with ?wmode=transparent and add wmode="Opaque" to the end of the <iframe ...>
  17.  
  18. <iframe width="625" height="352" src="http://www.youtube.com/embed/MCWJUSulnro?wmode=transparent" frameborder="0" allowfullscreen wmode="Opaque"></iframe>
  19. */
  20.  
  21.  
  22. add_filter( 'the_content' , 'mh_youtube_wmode' , 15 );
  23.  
  24. function mh_youtube_wmode( $content ) {
  25.  
  26. // Regex to find all <ifram ... > YouTube tags
  27. $mh_youtube_regex = "/\<iframe .*youtube\.com.*><\/iframe>/";
  28.  
  29. // Populate the results into an array
  30. preg_match_all( $mh_youtube_regex , $content, $mh_matches );
  31.  
  32. // If we get any hits then put the update the results
  33. if ( $mh_matches ) {;
  34.     for ( $mh_count = 0; $mh_count < count( $mh_matches[0] ); $mh_count++ )
  35.         {
  36.         // Old YouTube iframe
  37.         $mh_old = $mh_matches[0][$mh_count];
  38.  
  39.         $mh_new = str_replace( "?feature=oembed" , "?wmode=transparent" , $mh_old );
  40.         $mh_new = preg_replace( '/\><\/iframe>$/' , ' wmode="Opaque"></iframe>' , $mh_new );
  41.  
  42.         // make the substitution
  43.         $content = str_replace( $mh_old, $mh_new , $content );
  44.         }
  45.     }
  46. return $content;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement