YouTube video stream in a WordPress blog

by Mike Badgley on July 13, 2009

While working on a WordPress blog implementation for a client, I came up with a bit of an interesting solution for a feature request they had.

In short, they wanted to be able to show a list of videos from their YouTube channel, but be able to pick-and-choose which ones to display.

Originally I thought I’d just stick in an RSS feed and grab the last x videos, but since this didn’t allow for much (if any) customization, I was going to need to do it a different way.

Creating the Yahoo! Pipe

What I came up with was to create a pipe that allowed for three user inputs (since no more than three videos were to be displayed at any time). This input would be the unique ID that every YouTube video is associated with (i.e. http://www.youtube.com/watch?v=4ee4_Mso2_E), as shown in the screenshot below:

Yahoo! Pipes: User input

The next part was to take this input and use it with the URL Builder operator (as shown in the screenshot below) to assemble a URL that the pipe could use for fetching an RSS feed with. When using the publically-accessible API for YouTube, there is no option for grabbing a specific video – you can only return lists of a certain category or type. In this case, I just wanted the one video, so with my user input from above, I used this as a search parameter (q=youtube_video_id) within the URL.

Yahoo! Pipes: URL Builder

The final URL that I used for fetching a feed with (using the Fetch Feed module) looked something like this:

http://gdata.youtube.com/feeds/api/videos?qyoutube_video_id=&max-results=1&alt=rss

Integrating the Yahoo! Pipe within WordPress

For the life of me I couldn’t think of a good way of doing this while working on the project late last week. However, a fresh week (and extra sleep on the weekend didn’t hurt!) worked wonders as I determined the best course of action would be to create a dummy page within WordPress and then use custom fields as the means of storing the YouTube videos the client saw fit to display. Since this video feed appears on every page of the blog and doesn’t change from page-to-page or post-to-post, having a separate page that contained these custom fields seems to work best as I don’t want the client to have to update/add these fields for every post or page they add to the blog.