Thumbnail image doesn't show up in Shortcode output
A 'WordPress Shortcode' is being developed to display 'YouTube Channel Thumbnail' and 'Latest Playlist Thumbnail' when supplied with 'YouTube Channel ID' as follows.
[yt_insert channel_id=UCbCmjCuTUZos6Inko4u57UQ]
Shortcode implementation is as follows.
function yt_insert_decode( $atts ) {
$atts = shortcode_atts( array(
'channel_id' = ''
), $atts );
$api_key = 'YOUTUBE_API_KEY';
$channel_id = $atts['channel_id'];
$api_url = 'https://www.googleapis.com/youtube/v3/channels?part=snippet,contentDetailsid='
. urlencode($channel_id) . 'key=' . $api_key;
$api_response = wp_remote_get($api_url);
$api_response = json_decode( wp_remote_retrieve_body($api_response) );
$channel_thumbnail = $api_response-items[0]-snippet-thumbnails-default-url;
$playlist_id = $api_response-items[0]-contentDetails-relatedPlaylists-uploads;
$playlist_endpoint = 'https://youtube.googleapis.com/youtube/v3/playlists?part=snippetid='
. urlencode($playlist_id) . 'key=' . $api_key;
$api_response = wp_remote_get($playlist_endpoint);
$api_response = json_decode( wp_remote_retrieve_body($api_response) );
$playlist_thumbnail = $api_response-items[0]-snippet-thumbnails-default-url;
$response = 'img src=' . $channel_thumbnail . ' img src=' . $playlist_thumbnail . ' ';
return $response;
}
add_shortcode( 'yt_insert', 'yt_insert_decode' );
'Channel Thumbnail' DOES NOT show up while 'Playlist Thumbnail' shows up.
How can I change the code so that 'YouTube Channel Thumbnail' shows up in my Shortcode output?
Topic thumbnails shortcode youtube plugin-development plugins Wordpress
Category Web