Created
October 29, 2013 17:54
-
-
Save SanjeevMohindra/7219498 to your computer and use it in GitHub Desktop.
Video Embed Shortcode for YouTube with Schema Markup
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
// 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