Skip to content

Instantly share code, notes, and snippets.

@markthepixel
Forked from SanjeevMohindra/function.php
Created December 6, 2013 17:45
Show Gist options
  • Save markthepixel/7829081 to your computer and use it in GitHub Desktop.
Save markthepixel/7829081 to your computer and use it in GitHub Desktop.
// YouTube ShortCode [youtube src="" title="" duration="" thumbnail="" description=""]
function youtube_shortcode( $atts ) {
extract(shortcode_atts(array(
'src' => '',
'title' => '',
'duration' => '',
'thumbnail' => '',
'description' => ''
), $atts));
$video_tag = '<div itemprop="video" itemscope itemtype="http://schema.org/VideoObject">';
if ($title != ''){
$video_tag .= '<h2><span itemprop="name">' . $title . '</span></h2>';
}
if ($duration != ''){
$video_tag .= '<meta itemprop="duration" content="' . $duration . '" />';
}
if ($thumbnail != ''){
$video_tag .= '<meta itemprop="thumbnailUrl" content="' . $thumbnail . '" />';
}
$video_tag .= '<meta itemprop="embedURL" content="http://youtu.be/' . $src . '" />';
$video_tag .= '<div class="video-container"><iframe src="//www.youtube.com/embed/' .$src. '?hd=1" frameborder="0" allowfullscreen></iframe></div>';
if ($description != ''){
$video_tag .= '<span itemprop="description">' . $description . '</span>';
}
$video_tag .= '</div><br />';
return $video_tag;
}
add_shortcode('youtube', 'youtube_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment