Embed latest video from youtube channel

There isnt really much documentation out there to do this but I use this method and it works well for me.

To get started include the latest jquery library inside your <head> tags

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

Next on the spot where you want to add in the video drop in the following code:

<div id="static_video"></div>
    <script type="text/javascript">
        function showLatestVid(response) {
            if(response.data && response.data.items) {
                var items = response.data.items;
                if(items.length>0) {
                    var item = items[0];
                    var videoid = "http://www.youtube.com/embed/"+item.id;
                    console.log("Latest ID: '"+videoid+"'");
                    var video = "<iframe width='300' height='225' src='"+videoid+"' frameborder='0' allowfullscreen></iframe>"; 
                    jQuery('#static_video').html(video);
                }
            }
        }
    </script>
    <script type="text/javascript" src="https://gdata.youtube.com/feeds/api/users/*YOUR USERNAME*/uploads?max-results=1&orderby=published&v=2&alt=jsonc&callback=
showLatestVid"></script>

Just change the *YOUR USERNAME* to your channel name.

That should do it.

UPDATE:

This method doesnt work anymore 🙁 , but here is the updated method: Embed latest video from channel

Janes Oosthuizen

Author Janes Oosthuizen

Programmer and Tech Junky from Bloemfontein, South-Africa. I have been programming for 8 years in various languages including ( CSS, HTML, jQuery, PHP, MySQL, Wordpress and many other ).

More posts by Janes Oosthuizen

Leave a Reply