• About
  • Cases
  • Blog
  • Contact

Add custom block category

In WordPress 5.8.0, a filter named block_categories_all was introduced. It helps us add/remove/update Gutenberg, AKA the block editor’s categories. In the Toggle Block Inserter, there are 110+ blocks arranged into six categories. However, the total number of blocks is not documented yet. Every version adds blocks. By default, WordPress has six core categories.

  1. Text
  2. Media
  3. Design
  4. Widgets
  5. Theme
  6. Embeds

WordPress 5.0 introduced the block editor with Gutenberg 4.6.1. Then, the block_categories filter is used to add/remove/update these categories. In WordPress 5.8.0, the block_categories_all filter hook is used to add/remove/update these categories.

Let’s create a custom Gutenberg block category with the block_categories_all filter.

add_filter( 'block_categories_all', 'wpdevagent_block_category' );

function wpdevagent_block_category( $block_categories ) {

$block_categories[] = array(

'slug' => 'wpda-blocks',

'title' => __( 'WP Dev Agent blocks', ‘text-domain’ ),

);

return $block_categories;

}

To serve compatibility with WordPress 5.0 to 5.7, we can use the version_compare() function as

if ( version_compare( get_bloginfo( 'version' ), '5.8', '>=' ) ) {

add_filter( 'block_categories_all', 'wpdevagent_block_category' );

} else {

add_filter( 'block_categories', 'wpdevagent_block_category' );

}
I love to hear your ideas and thoughts
  • Mail
  • LinkedIn

Mrinal Haque

Solopreneur & WordPress expert

© 2025 ·

WP Dev Agent

· All rights reserved