Last active
June 16, 2016 08:01
-
-
Save alanpilloud/9aaab1f03155fa57c7e3bef60d603445 to your computer and use it in GitHub Desktop.
Embed youtube vidéos #wp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Responsive Youtube embeds. | |
* | |
* Adds bootstrap responsive embed markup and classes and avoid showing related | |
* videos at the end of the videos. | |
*/ | |
add_filter( 'embed_oembed_html', function( $html, $url, $attr, $post_ID ) { | |
if ( false !== stripos( $html, '<iframe ' ) && false !== stripos( $html, '.youtube.com/embed' ) ) { | |
//don't show related videos | |
$html = str_replace('?', '?rel=0&', $html); | |
$html = sprintf('<div class="embed-responsive embed-responsive-16by9">%s</div>', $html); | |
} | |
return $html; | |
}, 10, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment