Skip to content

Instantly share code, notes, and snippets.

@nielslange
Created March 11, 2018 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nielslange/5e1ec4c756dd04a4bb69841aef89ded5 to your computer and use it in GitHub Desktop.
Save nielslange/5e1ec4c756dd04a4bb69841aef89ded5 to your computer and use it in GitHub Desktop.
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