Hello.
I want to display one View Count of multiple YouTube videos on my website.
I'm not very tech-savvy, but here's a PHP code that I found on this website. With this code implemented in my website's theme file, and a Shortcode, I was able to display the View Count of one video.
How does this code need to be changed, so it displays the View Counts of multiple videos of my choosing?
Shortcode function:
function youtube_view_count_shortcode($params)
{
$videoID = $params['id'];
$json = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=statistics&id=" . $videoID . "&key=xxxxxxxxxxxxxxxxxxxxxxxx");
$jsonData = json_decode($json);
$views = $jsonData->items[0]->statistics->viewCount;
return number_format($views);
}
add_shortcode('youtube_view_count', 'youtube_view_count_shortcode');
Shortcode:
[[youtube_view_count id="UKuYgIBnqEA"]]
I would really appreciate any suggestions.
Thank you!