Snippets: Disable Related Youtube Videos

IMPORTANT: As of 2018 Google changed things so you can no longer disable related videos. Read more here.

// Disable Youtube related videos and enable "modest" branding mode for videos inserted into posts
add_filter( 'embed_oembed_html', function( $cache, $url, $attr, $post_ID ) {
	if ( strstr( $cache, 'youtube.com/embed/' ) ) {
		$cache = str_replace( '?feature=oembed', '?rel=0&modestbranding=1', $cache );
	}
	return $cache;
}, 10, 4 );

// Disable related Youtube videos for featured videos
add_filter( 'wpex_video_oembed_params', function() {
	return array(
		'youtube' => array(
			'rel' => 0
		),
	);
} );

Snippet Type: PHP

All PHP snippets should be added via a child theme's functions.php file or via the Code Snippets Plugin (or alternative plugin)