Last active
March 11, 2018 02:01
-
-
Save nielslange/3c9b0e601d16392eb262430e0bf34078 to your computer and use it in GitHub Desktop.
Show YouTube playlist videos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$api_request = 'https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&playlistId={PLAYLIST_ID}&key={YOUTUBE_API_KEY}'; | |
$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 ['contentDetails']['videoId'] ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment