Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Show YouTube channel videos
<?php
$api_request = 'https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&channelId={CHANNEL_ID}&key={YOUTUBE_API_KEY}&maxResults=3';
$api_response = wp_remote_get( $api_request );
$api_data = json_decode( wp_remote_retrieve_body( $api_response ), true );
if ( !empty($api_data['items']) ) {
$i = 0;
foreach ( $api_data ['items'] as $item ) {
printf( '<iframe width="300" height="160" src="https://www.youtube.com/embed/%s?&modestbranding=0&rel=0&controls=0&autohide=0&showinfo=0" frameborder="0" allowfullscreen></iframe>', $item ['id']['videoId'] );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment