Created
November 13, 2014 21:07
-
-
Save ronalfy/bc69eb249dcddee99766 to your computer and use it in GitHub Desktop.
WordPress YouTube Embed Overlay Into Lightbox
This file contains hidden or 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 | |
/*Place in functions.php or in custom plugin | |
Creates an overlay over the YouTube iFrame and allows you to pop-up the YouTube URL into a lightbox | |
*/ | |
add_filter( 'embed_oembed_html', 'opubco_youtube_parse', 10, 4 ); | |
function opubco_youtube_parse( $html, $url, $attr, $post_ID ) { | |
//Works well with: http://www.wonderplugin.com/wordpress-lightbox/ | |
if ( strstr( $url, 'youtu' ) ) { | |
if ( preg_match( '/src="([^"]+)"/', $html, $matches ) ) { | |
$embed_url = $matches[ 1 ]; | |
$anchor_styles = "position: absolute; width: 100%; height: 100%; top: 0; left: 0; background: transparent;"; | |
$html = sprintf( '<div class="youtube_iframe" style="position:relative">%s<a class="wplightbox" href="%s" style="%s"></a></div>', $html, esc_url( $embed_url ), $anchor_styles ); | |
} | |
} | |
return $html; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment