Codegena
automatically embed latest video from youtube channel

How To Automatically Embed The Latest Video From A YouTube Channel?

Embed the latest video from any youtube channel using an iframe or javascript code.

If you happen to own both a blog and a youtube channel, then you might have a “My Youtube Channel” widget on your site to display your latest videos. But updating this widget every time you upload a video can be a hefty and monotonous work. Not anymore! Now you can automatically embed the latest video from a youtube channel with a single line of code.

Auto Embed Latest Video from a Youtube Channel [knowing channel name]

<iframe width="600" height="340" src="https://www.youtube.com/embed?max-results=1&controls=0&showinfo=0&rel=0&listType=user_uploads&list=YOUR_CHANNEL_NAME_HERE" frameborder="0" allowfullscreen></iframe>

In the above code snippet, replace the channel name placeholder with your channel name. The snippet won’t work with channel IDs so make sure to add the correct channel name itself.

Copy paste the code into an online HTML code editor to see its working.

Auto Embed Latest Video from Youtube Channel [knowing channel ID]

If you don’t have a channel name then use the following code snippet. Replace the channel ID with your channel ID.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<iframe id="youtube_video" width="600" height="340" frameborder="0" allowfullscreen></iframe>

<script>
var channelID = "UC0xXUfNSFQN3qOmf_G_nT5w";
$.getJSON('https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fwww.youtube.com%2Ffeeds%2Fvideos.xml%3Fchannel_id%3D'+channelID, function(data) {
   var link = data.items[0].link;
   var id = link.substr(link.indexOf("=")+1);
    $("#youtube_video").attr("src","https://youtube.com/embed/"+id + "?controls=0&showinfo=0&rel=0");
});
</script>

Run the pen below to see this in action.

If this worked for you, please leave an upvote to my answer at StackOverflow.

Follow Us

Don't be shy, get in touch. We love meeting interesting people and making new friends.