Block Editor PHP Beginner

Turn Off the Block Directory

Stop the block inserter suggesting and installing blocks from WordPress.org when a search finds nothing.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 3 lines
add_action( 'init', function (): void {
	remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' );
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

When an inserter search finds no matching block, WordPress offers to install one from the plugin directory with a single click. On client sites that’s an easy way to end up with dozens of small, unvetted plugins. This snippet removes the feature.

How it works

The block directory is loaded by wp_enqueue_editor_block_directory_assets on enqueue_block_editor_assets. Removing that action means the editor never loads it, so searches simply show “No results”.

Things to watch

  • Administrators can still install plugins normally from Plugins → Add New.
  • Users without the install_plugins capability never see the block directory anyway.

How to test it

In the editor, search the inserter for a block you don’t have, such as “countdown”. You should see no install suggestions.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only