Skip to content

Instantly share code, notes, and snippets.

@SanjeevMohindra
Created October 29, 2013 17:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save SanjeevMohindra/7219498 to your computer and use it in GitHub Desktop.
Save SanjeevMohindra/7219498 to your computer and use it in GitHub Desktop.
Video Embed Shortcode for YouTube with Schema Markup
// 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