Created
February 26, 2018 13:10
-
-
Save damiencarbery/865d527a57a5255728176824759fdf7b to your computer and use it in GitHub Desktop.
Wrap oEmbed html in custom div - https://www.damiencarbery.com/2018/02/wrap-oembed-html-in-custom-div/
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 | |
/* | |
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