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:
- In your WordPress dashboard, go to “Appearance” > “Editor”.
- Select the “functions.php” file on the right-hand side of the screen.
- 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.
- 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.