Main menu

Post navigation

2012 – Embed Your YouTube Channel Into Your Website

Over the years it seems YouTube has made it more and more difficult, or tricky shall we say to embed your YouTube channel into your website. It used to be a simple click here and click there and you’re off to the races. Lately, it’s a little more painful. I’ve spent countless hours scouring the internet for ways to accomplish this task only to find thousands upon thousands of articles covering older methods of doing this that do not work anymore.

The other day I happened to stumble upon a great little website that offers the ability to edit code directly online and get immediate feedback for how that code will render. The website I found is known by some and probably unknown to many. It is called JsFiddle and can be found at www.jsfiddle.net I encourage coders to head on over and check it out. It is a great little online testing environment.

The code I found was created by a Simone Gianni using the JsFiddle site to draft it up and test it out. He has two versions online on JsFiddle. One version just shows your channel in a typical YouTube API Player and the other shows your channel with a nifty sidebar / carousel displaying other videos from your YouTube channel.

The sidebar / carousel version is the one that suits the needs for me and so I decided to go with that one. (I should also mention that the first version does not function in Internet Explorer). I thought it could be improved upon, so I added in a little extra code to not only just display thumbnails of the other videos, but also display their title off to the right as illustrated below. The scripting includes CSS, Javascript based on JQuery 1.5.2 and very minimal HTML code to place the container DIV on your page.

26 thoughts on “2012 – Embed Your YouTube Channel Into Your Website”

I’m a little confused by the HTML option on that page. It looks a little small. I’m trying to simply cut and paste into the HTML area of my new WordPress.org site. The carousel option would be perfect for me. Could you help a newbie out? I was hoping for an option that would just involve plugging in my YouTube channel name.

Hi guys. Jack, if you’d like to, send me an email and I’ll package up the files for you.

The implementation of this is easier than it looks. On the JsFiddle page for this code there are 4 boxes, the HTML, Javascript/JQuery, CSS and the Demo – live view of the code in action.

First and foremost, in the Javascript box / frame scroll to the bottom and change the User: “MagpieMedia1″ to your YouTube user name.

HTML: Place the content of the HTML box anywhere on your page where you would like the YouTube player to appear. Only include the DIV…./DIV portion, leave out the html and body tags as you’ll already have these tags on your page. They are only there to illustrate a complete, though very basic, HTML document.

Javascript: The code inside this frame should be placed on your document between the head tags, or for a little more of an efficient HTML document, just before the closing body tag. The best thing to do to properly grab this code, is to right click inside the live view frame and choose This Frame > View Source (browser dependent) or a similar function for your internet browser. Then there are 2 things to copy to your HTML document;

The Style content (the CSS) can either be placed in document between the head tags as it will appear in the Live View source code, or in an external style sheet with a reference to it in the head section.

The code works by first retrieving the library of videos from your channel and collecting all required data (thumbnails, title etc…). It then begins to create the content within the [div id=”player”]… [/div] element on your page. It is very important that this div has the ID of “player” as the code explicitly looks for this element ID on the page to place the player inside of. The CSS also styles this based on the “player” ID.

Would it be also possible to change the code to show a number of self defined videos, I mean to add a list of the video-IDs I wand to show, the first showing in the main window, the rest in the side bar?

Good morning. This looks like the perfect solution to what I require but I am stumped as to how to make this word using a wordpress theme ?
If it isnt too much hassle, could you please explain how to do this ? Many thnks

Super awesome code :D But it really needs some tweaking to do exactly what I need.. Can someone assist me doing a carrousel like this: http://www.ikosweb.com/regio/video.jpg
I need a carrousel *horizontal (with no thumbs, but players) Please if you know how the workaround I-d be extremely grateful!!

This code is absolutely great Tom!
I do have one question though.
My original idea using this code was to load a channel and break thumbnails down into categories (tags). But I couldn’t find any documentation to built that, so I am now trying first to load my channel with all available videos, and then load every single category in a hidden div – by using /-/tag_name in the url as described in Youtube API docs. I am using a variable to store the different category names and then parse them into the $.getJSON url. First call goes fine (all videos), but all calls after that (using my variable) breaks.
Any help would be appreciated. Thanks

Hey! Great code and I find it really useful. But what should I change if I want to have fx the video frame in a column of my webpage and the carousel with the other videos in another column of the same page? like having them in two different divs. I’m trying to understand it but I’m not a JavaScript expert at all.
Thank you for your help!

This is great! One question though. I want to have two columns for the thumbnails so need to wrap the image and desc inside of a DIV I can float. Tried a couple of methods but nothing really works. Any help would be great.

Here is a much easier way. Go an make a new playlist with every video you have. (select all check box) then make this play list private. play the play list. pause the video, Share the video, making sure the playlist option is selected. Click embedded link, copy past, change your width and high Bam! Done…

Here is mine
(FYI it’s my shitty travel blog, doesnt have to look pretty, just be easy for my family and friends to navigate and see whats up.. hence all the damn widgets.)

I got it to work. Question though. I am using it on a site where I am including it on each of the member pages that I’m building. Is it possible to have php print the youtube channel name instead of manually retyping?

I would imagine so. There may be a way to interact with the API to do it, otherwise it would involve some conditionals such as if pageUrl = page1 channel=thischannel1 elseif pageUrl=page2 channel = thischannel2. Or if you had a series of channels and pages to factor, a switch statement would be more efficient.

Either way you could build it as a function and call the function where the channel name is called in the Javascript. Just insert php tags and then echo the functions result.