Show Only Your Own Related Videos on YouTube Embeds
Adds rel=0 to YouTube embeds so the suggestions shown when a video ends come from the same channel instead of from other creators.
Opens WPIDE on
Code
add_filter( 'embed_oembed_html', function ( $html ) {
$result = preg_replace_callback( '#src="([^"]*youtube(?:-nocookie)?\.com/embed/[^"]*)"#i', function ( $m ) {
return 'src="' . esc_url( add_query_arg( 'rel', '0', html_entity_decode( $m[1] ) ) ) . '"';
}, $html );
return null === $result ? $html : $result;
}, 15 );
Notes
YouTube no longer allows hiding suggestions completely; rel=0 limits them to the video's own channel.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.