Hide Embed Blocks You Do Not Use
Keeps only the embed providers you choose, like YouTube and Vimeo, in the block inserter instead of dozens of services.
Opens WPIDE on
Code
// Embed variations to keep in the inserter.
$wpide_keep_embeds = array( 'youtube', 'vimeo', 'spotify' );
add_action( 'enqueue_block_editor_assets', function () use ( $wpide_keep_embeds ) {
wp_register_script( 'wpide-limit-embeds', false, array( 'wp-blocks', 'wp-dom-ready' ), '1.0', true );
wp_enqueue_script( 'wpide-limit-embeds' );
wp_add_inline_script(
'wpide-limit-embeds',
sprintf(
'wp.domReady(function(){var keep=%s;(wp.blocks.getBlockVariations("core/embed")||[]).forEach(function(v){if(keep.indexOf(v.name)===-1){wp.blocks.unregisterBlockVariation("core/embed",v.name);}});});',
wp_json_encode( array_values( $wpide_keep_embeds ) )
)
);
} );
Notes
Pasting a URL from a hidden provider may still create an embed.
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.