Skip to content

Instantly share code, notes, and snippets.

@mapsam
Last active August 29, 2015 14:06
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 mapsam/fb7d353a863a1b5d52e9 to your computer and use it in GitHub Desktop.
Save mapsam/fb7d353a863a1b5d52e9 to your computer and use it in GitHub Desktop.
YouTube shortcode embed
<?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;
}
<?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' );
.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