How to remove the download option on the video block in WordPress

In this post I will give a quick summary of how to remove the ability for users to use the built in “Download” functionality of the native video block. For reference, this is the “Download” option that shows when you click the three small dots at the bottom right corner of the video embed as pictured below:

Screenshot of Download option on video embed

Removing the download link only

The snippet below will use the render_block filter to add controlslist="nodownload" to the output of the html video markup, which will in turn disable the download link.

<?php
/**
 * Ensure download option is hidden on all core video blocks
 */
add_filter( 'render_block', 'wd_video_block_render', 10, 2 );
function wd_video_block_render( $output, $block ) {

	 // make sure this only runs on the core/video block
     if ( 'core/video' !== $block['blockName'] ) {
          return $output;
     }

     // use str_replace to add controlslist nodownload markup
     $output = str_replace(
          '<video controls',
          '<video controls controlslist="nodownload"', $output
     );

     //return
     return $output;
}

With that filter in place the option to download has been removed:

Screenshot of video embed with Download option removed

If you would like to take it a step further and remove all of the controlslist options we can do so.

Removing all video controls

The snippet below uses the same method, but adds some additional markup that will remove the three dots and all the options that reside within it:

<?php
/**
 * Ensure download options are hidden on all core video blocks
 */
add_filter( 'render_block', 'wd_video_block_render', 10, 2 );
function wd_video_block_render( $output, $block ) {

	 // make sure this only runs on the core/video block
     if ( 'core/video' !== $block['blockName'] ) {
          return $output;
     }

     // use str_replace to add controlslist options to remove three dots
     $output = str_replace(
          '<video controls',
          '<video controls controlslist="nodownload noplaybackrate noremoteplayback" disablePictureInPicture', $output
     );

     //return
     return $output;
}

As you can see, I’ve added some additional markup to the output that will remove the playbackrate removeplayback and PictureInPicture options, which in turn removes the three dots UI completely.

Screenshot of video embed with controlsList UI removed

You could extend this as needed to add any other modifications you’d like to the html5 video markup.

Comments

  1. R. says:

    Thank you for sharing these great tutorials. I love your WordPress tips and tutorials, these are very useful and I use them a lot on my websites. It will be great to see more of them.

  2. Philippe says:

    Hi. I need to know where to put the snippet code please.

    1. Matt Whiteley says:

      Hey Phillippe,

      Depends on the theme you’re using, but typically in the functions.php file will work best.

      Cheers,

      Matt

Leave a Reply

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