Stream Your YouTube Channel On A Page Inside Your WordPress Website

WordPress shortcodes are great. They let you perform complex operations or display dynamic content with just a tiny bit of text in any page or post.

I recently needed a way to embed the most recent videos from a Youtube channel (very dynamic information) in a WordPress page, so I decided to write a shortcode for it.

[divider /]

The code is actually pretty simple. Just add the following to your theme’s functions.php file:

COPY CODE BELOW

function youtube_feed_shortcode($atts)
{
// Defaults:
extract(shortcode_atts(array(
'user' => 'mrinternettips', // youtube user
'limit' => 5, // maximum number of videos
'height' => 385, // video height
'width' => 480 // video width
), $atts));
$data = @json_decode(file_get_contents('http://gdata.youtube.com/feeds/api/users/'.$user.'/uploads?alt=json'), TRUE);
$counter = 0;
$content = '
'; foreach($data['feed']['entry'] as $vid) { $url = $vid['media$group']['media$content'][0]['url']; $title = $vid['title']['$t']; $ycontent = $vid['content']['$t']; $content.= ''.''.''.''.''. '
'.$title.'
'. '
'.$ycontent.'
'."n"; $counter++; if($counter == $limit) { break; } } $content .= '
'; return $content; } add_shortcode('youtubefeed', 'youtube_feed_shortcode');

The shortcode below is completely configurable.

[youtubefeed user="YourChannel Name Here" limit="3" height="385" width="560"]

You can change any option as needed.

You might have noticed the code gives each element a particular class to make it CSS friendly. All you have to do is add CSS rules for three classes: .youtubefeed, .youtubetitle, and .youtubecontent.

[divider /]

My stylesheet looks like this: (this will be your style.css file)

COPY CODE BELOW

.youtubefeed {
margin: 10px;
text-align: center;
}
.youtubetitle {
font-size: 1.6em;
font-weight: bold;
margin: 3px;
}
.youtubecontent {
margin-bottom: 30px;
text-align: left;
}

Other Plugin That Will Do This:

TubePress

TubeMatic

Previous Floating Share Plugin for Wordpress
Next Top 10 FREE Wordpress Plug-ins That Are A Must To Have

About author

Jarrett Gucci
Jarrett Gucci 289 posts

Jarrett Gucci is the owner of Dynasty Web Solutions. A full service Internet presence provider specializing in WordPress development for business owners. Jarrett Gucci along with his team of professionals have designed over 400 WordPress websites. Jarrett Gucci believes strongly in creating websites that are unique, functional and generate referrals.

You might also like

WordPress Themes 0 Comments

Top 9 Pinterest Style WordPress Themes

EcoStrips Pinterest Style WordPress Theme EcoStrips is a premium WordPress theme from iDesignEco with a dynamic post wall mashup design inspired by Pinterest. The theme has a dynamic mobile responsive layout, with the

WordPress Resources 0 Comments

WordPress Maintenance Packages

The WordPress Maintenance packages are monthly plans that we offer to take all the stress off your shoulders for managing the technical side of your business. Plus, you will get

WordPress Resources 0 Comments

8 greatest advantages of WordPress

WordPress is the greatest blogging platform till date. This statement is admitted by the top bloggers of the world. Blogs like Techcrunch, Readwriteweb, Mashable and Problogger runs on WordPress. So

WordPress Resources 0 Comments

Embed Facebook Group Posts on a Website Using WordPress

I searched high and low for a solution to embed Facebook group posts on a website. Why you ask? Well Facebook Groups have become a very important piece to my

WordPress Resources 0 Comments

MUST HAVE WordPress Plugins for every install

This is my list of MUST HAVE WordPress Plugins that should be included in ever install.WordPress Plugins can be extremely useful for building your website and making it successful. There

WordPress Resources 0 Comments

The Best Way to Backup WordPress – Step by Step

Backup Before You Crackup WordPress is such an awesome software for building your website or blog but we all know there can be many plugins and core updates that happen

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply