Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
Created February 26, 2018 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damiencarbery/865d527a57a5255728176824759fdf7b to your computer and use it in GitHub Desktop.
Save damiencarbery/865d527a57a5255728176824759fdf7b to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: oEmbed wrapper div
Plugin URI: https://www.damiencarbery.com/2018/02/wrap-oembed-html-in-custom-div/
Description: Add a wrapper div to YouTube embeds.
Author: Damien Carbery
Version: 0.1
*/
function dcwd_youtube_wrapper( $html, $url, $attr, $post_ID ) {
$classes[] = 'social-embed-container';
if (stripos($url, "youtube.com/") !== FALSE || stripos($url, "youtu.be/") !== FALSE) {
$classes[] = 'video-container';
}
return '<div class="' . implode( ' ', $classes ) . '">' . $html . '</div>';
}
add_filter( 'embed_oembed_html', 'dcwd_youtube_wrapper', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment