Skip to content

Instantly share code, notes, and snippets.

@someguy9
Created October 15, 2020 14:15
Show Gist options
  • Save someguy9/41d5671383715176b859586dc636f300 to your computer and use it in GitHub Desktop.
Save someguy9/41d5671383715176b859586dc636f300 to your computer and use it in GitHub Desktop.
Auto wrap YouTube video embeds in WordPress with a div
<?php
add_filter('embed_oembed_html', function ($html, $url, $attr, $post_id) {
if(strpos($html, 'youtube.com') !== false || strpos($html, 'youtu.be') !== false){
return '<div class="responsive-embed-container embed-responsive-16by9">' . $html . '</div>';
} else {
return $html;
}
}, 10, 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment