How to disable Youtube related videos?

[ad_1]

If you would like to remove related videos on all embedded YouTube videos on your site, follow these steps to update the Gutenberg YouTube Block:

  1. In your WordPress dashboard, go to “Appearance” > “Editor”.
  2. Select the “functions.php” file on the right-hand side of the screen.
  3. Add the following code to the end of the file:
function add_rel_to_youtube_embed( $html ) {
    if ( strpos( $html, "<iframe" ) !== false ) {
        $html = str_replace( "?feature=oembed", "?feature=oembed&rel=0", $html );
    }
    return $html;
}
add_filter( 'embed_oembed_html', 'add_rel_to_youtube_embed', 10, 1 );

This code adds a filter to modify the YouTube embed code and add the “rel=0” parameter to the URL.

  1. Click the “Update File” button to save your changes.

After updating the functions.php file, the “rel=0” parameter should be added to all YouTube videos embedded using the Gutenberg YouTube block. If you have already added a YouTube block to your post or page, you may need to remove the block and add it again for the changes to take effect.

Thank you very much @abretado1985 !!

The code snippet works perfectly.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer