I’m trying to figure out how to stop YouTube from showing related videos at the end of my embedded player. I’m using the JavaScript API but can’t find a clear way to do this.
Here’s what I’ve got so far:
let videoPlayer = new YT.Player('videoContainer' + videoNum, {
height: '480',
width: '720',
videoId: videoCode
});
I tried adding ?rel=0 to the videoId and even put relatedVideos: false in the options, but neither worked.
Is there a secret setting I’m missing? How can I turn off those suggested videos using the JavaScript API? Any help would be awesome!
I’ve been down this road before, and it can be frustrating. The trick is to use the ‘playerVars’ option in your YT.Player configuration. Here’s what worked for me:
The ‘rel’: 0 parameter should disable related videos at the end. ‘modestbranding’: 1 is a bonus that removes most YouTube branding, which I find cleaner.
Keep in mind that YouTube’s policies sometimes change, so this might not work forever. But it’s been reliable for me in recent projects. Hope this helps solve your issue!
I’ve encountered this issue before, and it can be quite tricky. While the ‘rel’ parameter in playerVars is a good start, it’s not always 100% effective. In my experience, combining multiple parameters yields better results. Try this approach:
This configuration disables related videos, hides video info, turns off annotations, and disables fullscreen. It’s worked consistently for me across various projects. Just be aware that YouTube’s API can change, so always check their latest documentation for any updates.
I’ve wrestled with this issue in a few projects, and I’ve found that sometimes you need to get a bit creative. While the playerVars approach is solid, I’ve had success by combining it with some CSS trickery. Here’s what worked for me:
First, set up your player with the usual playerVars:
This CSS targets the overlay that YouTube uses to display related videos. By hiding it, you ensure that even if YouTube tries to show suggestions, they won’t appear.
It’s not the most elegant solution, but it’s been reliable in my experience. Just remember to test thoroughly, as YouTube’s interface can change unexpectedly.
I’ve dealt with this issue in several projects. While the ‘rel’ parameter is often suggested, it’s not always foolproof. In my experience, a more robust approach involves using a combination of player parameters and some additional JavaScript.
This configuration not only attempts to disable related videos but also stops the player when the video ends, preventing any suggestions from appearing. It’s been the most reliable method in my projects so far.