Embedding your latest Youtube video

I was wanting to embed my latest youtube video on my website. What I mean is, I wanted a simple embed script that would always show the latest video I’d uploaded. After discovering that Youtube doesn’t provide a simple way to do this I started googling to see if someone had written a script for it. I had no luck, so I’ve written one.

Taking use of some simple web scraping from the YouTube API, it’ll take the latest video from any Youtuber and embed a player with the what ever size the coder chooses.

It’s written in PHP and is just one function that can be called anywhere on your page. It takes three parameters: the username, the desired video width and the desired video height.

So here’s the first part which I recommend you place at the top of your page, I’ve commented it to help show what’s happening.

[code lang=”php”]
‘;
//echo the embed code
echo $embedCode;
}
else
{
echo ‘No Video Found.’;
}
}
?>
[/code]

So the above is the actual function and below is how we call it, we just call the function stating the username, width and height of the video and it’ll do the rest. So just place the following bit where ever you want the video to appear in your code.

[code lang=”php”]

[/code]

You can see this code in action on my Videos Page. Feel free to use it, I’d love to know what you think in the comments below.

Published byapbarratt

I own this here website, bow down before your God!