Skip to content

Instantly share code, notes, and snippets.

@alanpilloud
Last active June 16, 2016 08:01
Show Gist options
  • Save alanpilloud/9aaab1f03155fa57c7e3bef60d603445 to your computer and use it in GitHub Desktop.
Save alanpilloud/9aaab1f03155fa57c7e3bef60d603445 to your computer and use it in GitHub Desktop.
Embed youtube vidéos #wp
<?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