-
-
Save collegeman/1987525 to your computer and use it in GitHub Desktop.
Revisions
-
collegeman renamed this gist
Mar 6, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
collegeman revised this gist
Mar 6, 2012 . 1 changed file with 9 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ <?php /** * Youtube Shortcode Solution * @@ -14,14 +15,18 @@ function youtube($atts) { extract(shortcode_atts(array( "value" => 'http://', "width" => '590' ), $atts)); if ($oembed = coreylib('http://www.youtube.com/oembed?url='.urlencode($value).'&format=xml','1 month')) { if (preg_match('#vi/(.*)/#i', $oembed->get('thumbnail_url'), $matches)) { $id = $matches[1]; } else if (preg_match('#v=(.*)&?#i', $oembed->get('thumbnail_url'), $matches)) { $id = $matches[1]; } else { return '<a href="'.$value.'">'.$value.'</a>'; } $newHeight = round($width * (string) $oembed->get('height') / (string) $oembed->get('width')); -
coreyweb renamed this gist
Mar 6, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
coreyweb created this gist
Mar 6, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ /** * Youtube Shortcode Solution * * Set your desired width for all the videos on your site (below) * Paste any Youtube video link in the shortcode, using this format, i.e.: * [youtube value="http://www.youtube.com/watch?feature=player_embedded&v=GGT8ZCTBoBA"] * This code will automatically resize your video to the appropriate size and aspect ratio. * Modify the width value (set to 590 here), and the iframe code below to your desired settings. * This requires coreylib (coreylib.com) * Shortcode by coreyweb: https://github.com/coreyweb * and collegeman: https://github.com/collegeman */ function youtube($atts) { extract(shortcode_atts(array( "value" => 'http://', "width" => '590', // "height" => '350' ), $atts)); if ($oembed = coreylib('http://www.youtube.com/oembed?url='.urlencode($value).'&format=xml','1 month')) { preg_match('#vi/(.*)/#i', $oembed->get('thumbnail_url'), $matches); $id = $matches[1]; $newHeight = round($width * (string) $oembed->get('height') / (string) $oembed->get('width')); return '<iframe width="'.$width.'" height="'.$newHeight.'" src="http://www.youtube.com/embed/'.$id.'?rel=0&wmode=transparent" frameborder="0" allowfullscreen></iframe>'; } } add_shortcode("youtube", "youtube");