Turning Off The Block Directory

The block editor tries to suggest new blocks to install when administrators create posts. After some digging, I figured out how to completely disable and remove this feature. As great as the block directory is for me personally, it’s not good for professional sites where a client expects a streamlined or controlled environment.

To do this, there are 2 methods.

In method 1, we need to unregister the block-directory plugin using unregisterPlugin/ wp.plugins.unregisterPlugin. This PHP inserts that code when the block editor loads:

function tomjn_remove_block_directory() {
	wp_add_inline_script(
		'wp-block-editor',
		"wp.domReady( () => wp.plugins.unregisterPlugin( 'block-directory' ) )"
	);
}
add_action( 'admin_enqueue_scripts', 'tomjn_remove_block_directory' );

In method 2, we remove the actions that enqueue the block directory javascript:

add_action(
    'admin_init',
    function() {
        remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' );
        remove_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_block_editor_assets_block_directory' );
    }
);

Both methods work on their own, here’s the before and after:

2 screenshots of the inserter. On the left is the standard inserter with the block directory, on the right is the inserter once the block directory is disabled

2 thoughts on “Turning Off The Block Directory

  1. If the file system isn’t writable this will also disable the block directory. For example, this means it won’t be active when DISALLOW_FILE_MODS is defined and true.

  2. Pingback: WP Weekly 39 / Missing / Taming Blocks, Better Social, Patterns Directory

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.