When you embed a YouTube video onto your site, odds are you aren’t going to want the matrix of ‘Related Videos’ to display once your video is over. Generally speaking, there is a toggle button to turn this off under the embedding options, but lately I’ve found some videos where this does not display. Fortunately, it’s easy enough to get this functionality, even when YouTube doesn’t give it to you.All you need to do is add “?rel=0” to the end of the video URL in the iFrame. Let’s take a look at some examples.
Vanilla YouTube Video
To start, let’s just take the standard code YouTube gives you to embed onto your site. The video plays just fine, but at the end you get this ugly matrix of other videos to watch.
<iframe width=”500″ height=”281″ src=”http://www.youtube.com/embed/cPHneDzQkoE” frameborder=”0″ allowfullscreen></iframe>
YouTube Video Embedded with ?rel=0
By simply adding “?rel=0″ to the end of the URL in the iFrame, the related videos are stripped out.
<iframe width=”500″ height=”281″ src=”http://www.youtube.com/embed/cPHneDzQkoE?rel=0″ frameborder=”0” allowfullscreen></iframe>
If you’re a WordPress user, you might want to check out another brief post about enabling iFrames in WordPress (which generally strips them out for security reasons).