Last active
August 29, 2015 14:06
-
-
Save mapsam/fb7d353a863a1b5d52e9 to your computer and use it in GitHub Desktop.
YouTube shortcode embed
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 // get youtube ID function | |
function get_youtube_id($url) { | |
$query_string = array(); | |
parse_str(parse_url($url, PHP_URL_QUERY), $query_string); | |
$id = $query_string["v"]; | |
return $id; | |
} |
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 | |
function youtube_shortcode( $atts ) { | |
$url = str_replace('=', '', $atts[0]); | |
//echo '<div class="video">'; | |
//echo '<iframe src="http://youtube.com/embed/'.$videoID.'?rel=0" frameborder="0" allowfullscreen></iframe>'; | |
//echo '</div>'; | |
return '<div class="video"><iframe src="http:'.$url.'?rel=0" frameborder="0" allowfullscreen></iframe></div>'; | |
} | |
add_shortcode( 'youtube', 'youtube_shortcode' ); |
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
.video { | |
position: relative; | |
padding-bottom: 56.25%; | |
height: 0; | |
overflow: hidden; | |
width:100%; | |
} | |
.video iframe { | |
position: absolute; | |
width:100%; | |
height:100%; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment