How to show latest uploaded video from YouTube channel using PHP script


Are you looking for the Latest Video Post from Youtube Channel? Here is the right place to get the solution. AkashWagh has found PHP script which can get easy latest uploaded video from YouTube channel using PHP script

Today I will let you know that how to get Youtube Channel’s Latest video post in PHP. To get that latest post from YouTube you need to add the following code to the page where you want to show post.

For the WordPress site, a user could use this code in a custom plugin or can create an own plugin using below code.

For below code, you must have following details with you before starting the implementation.

$channelId = 'Enter Your Channel Name'; 
$maxResults =1; 
$API_key = 'Enter Your API Key'; 
$video_list = json_decode(file_get_contents(''.$channelId.'&maxResults='.$maxResults.'&key='.$API_key.'')); foreach($video_list->items as $item)
            $created_time = $item->snippet->publishedAt;
            $description = $item->snippet->description;
            $converted_date_time = date( 'dS M Y', strtotime($created_time));
             echo $converted_date_time; 
             echo '<img src="'.$item->snippet->thumbnails->medium->url.'" alt="'.$item->snippet->title.'" class="img-responsive" height="80px" />';
             echo (isset($description) && $description !="" ) ? $description: $item->snippet->title;
        }else if(isset($item->id->playlistId)){
            echo '
<li id="'. $item->id->playlistId .'" class="col-lg-3 col-sm-6 col-xs-6 youtube-playlist"><a href="#'. $item->id->playlistId .'" title="'. $item->snippet->title .'"><img src="'. $item->snippet->thumbnails->medium->url .'" alt="'. $item->snippet->title .'" class="img-responsive" height="130px" />
<h2>'. $item->snippet->title .'</h2>

<span class="glyphicon glyphicon-play-circle"></span></a></li>';


Note: Please replace the channel Id and APY key with your details and change the CSS as per your requirement.

Please feel free to ask any queries related to it or you could pass it in below comments.



4 + eleven =