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:
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.Pingback: WP Weekly 39 / Missing / Taming Blocks, Better Social, Patterns Directory