Removing unrelated videos from Youtube embeds in Gutenberg

Notice I hope no unrelated videos at the end of the above embed.

On Slack in Make WordPress I came across a thread which talked about improving the Youtube embed block in Gutenberg and one of the things mentioned was removing the unrelated videos from a Youtube embed. I have tried it out on a client site I am working on and it worked fine.

The link to WP for the Win blog post about removing unrelated videos from Youtube embed block in Gutenberg was mentioned.

Example from adding the code to the Pro version of Code Snippets.

Remove unrelated videos at the end of a youtube embed Gutenberg WordPress Code Snippet plugin
Remove unrelated videos at the end of a youtube embed Gutenberg WordPress Code Snippet plugin

Remove unrelated videos from Youtube embed

The following code can be added to a child theme functions file or a code snippet plugin.

// Add modestbranding to WP Gutenberg Video Blocks
// https://wpforthewin.com/remove-related-videos-wp-gutenberg-embed-blocks/
function wpftw_modest_youtube_player( $block_content, $block ) {
  if( in_array($block['blockName'], ['core-embed/youtube', 'core-embed', 'core/embed'] ) ) {
    $block_content = str_replace( '?feature=oembed', '?feature=oembed&modestbranding=1&showinfo=0&rel=0', $block_content );
  }
  return $block_content;
}
add_filter( 'render_block', 'wpftw_modest_youtube_player', 10, 3);

Here is a Gutenberg issue: Enhance YouTube embed block with player parameters

Here is also a enhanced Youtube embed block WordPress plugin

An additional resource: https://embedresponsively.com/ (Will give you code to make the video responsive.)

Share the article:

Leave a Reply

Your email address will not be published. Required fields are marked *