Each time we use the Video module to display a specific video from YouTube, once it is done playing, at the end, YouTube will automatically show other related videos.
We can stop that behavior using a custom JS code.
Before writing any JS code, edit the Video Module and in Advanced Tab > CSS ID & Classes > CSS Class, type in divi-no-yt-related-videos
.
This will be a CSS class that we will be using in the following JS code.
<script id="remove-related-youtube-videos">
(function ($) {
$(document).ready(function () {
if ($('.divi-no-yt-related-videos').length) {
$('.divi-no-yt-related-videos iframe').attr('src', function (i, val) {
return val + '&rel=0';
});
}
});
})(jQuery);
</script>
The jQuery code can be copied/pasted into Divi > Theme Option > Integration tab > Header.
Important Note: The above code will show only related videos from the same channel as the video just played.
If the video used in the video module is not part of a channel, the rel=0
attribute will still display any relevant, public video at the end of your video.