Programming

Get the youtube video ID from url

If you are struggling to get the video id (i.e.v=id)  from YouTube’s URL, use the below function.

function get_youtube_video_id($youtubeUrl) {
    preg_match_all("#(?<=v=|v\/|vi=|vi\/|youtu.be\/)[a-zA-Z0-9_-]{11}#", $youtubeUrl, $matches);
    $youtubeVideoID = $matches[0][0];
    return $youtubeVideoID;
}

$youTubeVideoID = get_youtube_video_id('https://www.youtube.com/watch?v=Zftx68K-1D4');

Views: 114

Standard

4 thoughts on “Get the youtube video ID from url

  1. Whats up this is kind of of off topic but I was wanting to know
    if blogs use WYSIWYG editors or if you have to manually code with HTML.
    I’m starting a blog soon but have no coding skills so I wanted to get advice from someone with experience.
    Any help would be greatly appreciated!

    • kabita@admin says:

      You don’t need to add any code for publishing the contents in the blog i.e you don’t need to have any coding skills for running the blog, unless you want to modify the themes styling , or add your own styles/module in the blog

  2. kabita@admin says:

    In the YouTube url you can see the combination of numbers and letter after an equal sign(=), which is the ID of YouTube video.

    Suppose , https://www.youtube.com/watch?v=ZdP0KM49IVk is YouTube video url. In this url ‘ZdP0KM49IVk’ is the ID of video.

    You can directly embed YouTube video in WordPress using an

Comments are closed.