Last active
December 17, 2015 11:09
-
-
Save lucasstark/5600480 to your computer and use it in GitHub Desktop.
// Minimal YouTube & Vimeo embeds
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
// Minimal YouTube & Vimeo embeds | |
function theme_oembed_get($url, $args = '') { | |
if (preg_match("/youtube.com\/watch\?v=([^&]+)/i", $url, $aMatch)) { | |
return '<iframe width="' . $args['width'] . '" height="' . $args['height'] . '" src="http://www.youtube.com/embed/' . $aMatch[1] . '?loop=1&modestbranding=1&rel=0&showinfo=0&autohide=1" frameborder="0" allowfullscreen></iframe>'; | |
} | |
if (preg_match("/youtube.com\/watch\?feature=player_embedded&v=([^&]+)/i", $url, $aMatch)) { | |
return '<iframe width="' . $args['width'] . '" height="' . $args['height'] . '" src="http://www.youtube.com/embed/' . $aMatch[1] . '?loop=1&modestbranding=1&rel=0&showinfo=0&autohide=1" frameborder="0" allowfullscreen></iframe>'; | |
} | |
if (preg_match("/youtube.com\/watch\?feature=player_detailpage&v=([^&]+)/i", $url, $aMatch)) { | |
return '<iframe width="' . $args['width'] . '" height="' . $args['height'] . '" src="http://www.youtube.com/embed/' . $aMatch[1] . '?loop=1&modestbranding=1&rel=0&showinfo=0&autohide=1" frameborder="0" allowfullscreen></iframe>'; | |
} | |
if (preg_match("/vimeo.com\/([^&]+)/i", $url, $aMatch)) { | |
return '<iframe width="' . $args['width'] . '" height="' . $args['height'] . '" src="http://player.vimeo.com/video/' . $aMatch[1] . '?title=0&byline=0&portrait=0" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'; | |
} | |
require_once( ABSPATH . WPINC . '/class-oembed.php' ); | |
$oembed = _wp_oembed_get_object(); | |
return $oembed->get_html($url, $args); | |
} | |
function theme_oembed_get_youtube_video_id($url) { { | |
$parsedUrl = parse_url($url); | |
if ($parsedUrl === false) | |
return false; | |
if (!empty($parsedUrl['query'])) { | |
$query = array(); | |
parse_str($parsedUrl['query'], $query); | |
if (!empty($query['v'])) | |
return $query['v']; | |
} | |
if (strtolower($parsedUrl['host']) == 'youtu.be') | |
return trim($parsedUrl['path'], '/'); | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment