• Resolved Tim Burkart

    (@bigmoxy)


    Hi,

    I am using the Youtube embed block and want to know how to disable related videos. I have tried editing the block as HTML and appending rel=0 but that results in a block editor error.

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.

    Thread Starter Tim Burkart

    (@bigmoxy)

    Thank you very much @abretado1985 !!

    The code snippet works perfectly.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to disable Youtube related videos?’ is closed to new replies.