Last active
December 14, 2015 15:08
-
-
Save vctrfrnndz/5105351 to your computer and use it in GitHub Desktop.
Youtube id regular expression (getting url from Wordpress meta tag)
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
$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