I’m trying to come up figure out a way to automatically go to to the next post in line on a wordpress site when a youtube video in the current post has stopped playing. The youtube videos are not embeded with the youtube API but rather embeded using the iframe.
Does anyone have any idea how to do this?
I’m adapting the code from this answer YouTube iframe API and WordPress. You’d have to rewrite your posts to use a shortcode or adapt the idea to your current configuration.
Videos are embeded using a shortcode pointing to the YT ID:
[ytplayer id="M7lc1UVf-VE"]
, and the playback uses YT iFrame API.We check the next post link using
get_next_post()
(could beget_previous_post()
) and pass that to the JavaScript code. When the video ends, and if we have an actual next post, it will jump to the link: