Gutenberg Categories

The following posts are coming up!

Recent Posts



No, this isn’t something snazzy about doing cool things with categories within Gutenberg (although you could). This is about making a section for your own blocks. A category.

What’s a Category?

I’m incredibly lazy, so when I use blocks, I type /head and make sure I get the right block, hit enter, and keep on typing.

The slash command at work!

But. Sometimes I think I need a specific block and I don’t know the name, so I click on the circle + sign and I get a list of categories!

Block categories

You won’t see reusable if you didn’t make some, but the point is that you could make a custom category for your custom blocks.

Show me the code!

Glad you asked! You’re gonna love this one.

add_filter( 'block_categories', function( $categories, $post ) {
	return array_merge(
		$categories,
		array(
			array(
				'slug'  => 'halfelf',
				'title' => 'Half-Elf',
			),
		)
	);
}, 10, 2 );

Yep. That’s it! It’s an array, so you can add more and more and more as you want. Don’t go too wild, though, or you’ll make it too long.


Posted

in

by

%d bloggers like this: