Skip to content

Instantly share code, notes, and snippets.

@vctrfrnndz
Last active December 14, 2015 15:08
Show Gist options
  • Save vctrfrnndz/5105351 to your computer and use it in GitHub Desktop.
Save vctrfrnndz/5105351 to your computer and use it in GitHub Desktop.
Youtube id regular expression (getting url from Wordpress meta tag)
$video_url = get_post_meta( get_the_ID(), 'mb_youtube_url', true );
// Parse video ID from given url
if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $video_url, $match)) {
$video_id = $match[1]; // Return video ID
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment