Created
March 25, 2014 18:01
-
-
Save dobsondev/9767514 to your computer and use it in GitHub Desktop.
Shortcode for Embedding a YouTube Video - Used in DobsonDev Shortcodes Plugin for WordPress
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 | |
/* Adds a shortcode to embed a YouTube video */ | |
function dobson_embed_youtube($atts) { | |
extract(shortcode_atts(array( | |
'video' => "Invalid Video ID", | |
'width' => "560", | |
'height' => "315", | |
), $atts)); | |
$source_headers = @get_headers("http://youtube.com/watch?v=" . $video); | |
if (strpos($source_headers[0], '404 Not Found')) { | |
return '<p> Invalid YouTube video ID. Please check your YouTube video ID. </p>'; | |
} else { | |
return '<iframe width="' . $width . '" height="' . $height . '" src="//www.youtube.com/embed/' . $video | |
. '" frameborder="0" allowfullscreen></iframe>'; | |
} | |
} | |
add_shortcode('embedYouTube', 'dobson_embed_youtube'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment