Youtube

function get_youtube_videos() {
$api_key = ‘AIzaSyBT89FRxPEp2e0Xx5wQzVD61NygaOXrw50’;
$channel_id = ‘UCPTUBrm5TUsBduDlUVBVGwQ’;
$api_url = “https://www.googleapis.com/youtube/v3/search?key={$api_key}&channelId={$channel_id}&part=snippet,id&order=date&maxResults=10”;

$response = wp_remote_get($api_url);
if (is_wp_error($response)) {
return [];
}

$data = json_decode(wp_remote_retrieve_body($response), true);
return $data[‘items’];
}