Your Own Block Category at the Top of the Inserter
Adds a block category named after your site to the top of the block inserter and moves custom blocks with a chosen namespace into it, so editors find your bespoke blocks first.
Opens WPIDE on
Code
// Block name prefixes that belong in the category.
$wpide_block_namespaces = array( 'wpide/' );
add_filter( 'block_categories_all', function ( $categories ) {
array_unshift( $categories, array(
'slug' => 'site-blocks',
'title' => get_bloginfo( 'name' ),
'icon' => null,
) );
return $categories;
} );
add_filter( 'register_block_type_args', function ( $args, $name ) use ( $wpide_block_namespaces ) {
foreach ( $wpide_block_namespaces as $prefix ) {
if ( 0 === strpos( $name, $prefix ) ) {
$args['category'] = 'site-blocks';
}
}
return $args;
}, 10, 2 );
Notes
Set $wpide_block_namespaces to the prefix of your blocks, such as acme/ or wpide/.
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.