Do Not Preload Audio and Video Files
Sets audio and video players to preload nothing until the visitor presses play, saving bandwidth on pages with several media files.
Opens WPIDE on
Code
$wpide_no_preload = function ( $out ) {
$out['preload'] = 'none';
return $out;
};
add_filter( 'shortcode_atts_audio', $wpide_no_preload );
add_filter( 'shortcode_atts_video', $wpide_no_preload );
$wpide_no_preload_block = function ( $content ) {
$content = preg_replace( '/\spreload="[^"]*"/i', '', $content );
return preg_replace( '/<(audio|video)\b/i', '<$1 preload="none"', $content );
};
add_filter( 'render_block_core/audio', $wpide_no_preload_block );
add_filter( 'render_block_core/video', $wpide_no_preload_block );
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.