Advertisement
jan_dembowski

youtube-oembed.php

Feb 17th, 2013
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 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.2
  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. add_filter('embed_oembed_html','mh_adjustyoutube',10,3);
  22. function mh_adjustyoutube( $html, $url, $args ) {
  23.         if ( strstr($url, 'youtube.com') ) {
  24.         // Replace ?feature=oembed
  25.                 $mh_new = str_replace( "?feature=oembed" , "?wmode=transparent" , $html );
  26.         // Append wmode="Opaque"
  27.                 $mh_new = preg_replace( '/\><\/iframe>$/' , ' wmode="Opaque"></iframe>' , $mh_new );
  28.                 $html = $mh_new;
  29.         }
  30.     // Modified or not return $html
  31.         return $html;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement