unregister_block_pattern_category()WP 5.5.0

Deletes a previously registered block pattern category.

After deletion, the category will no longer be available in the category list in the block editor.

The function is useful when you need to hide unnecessary or conflicting pattern categories registered by core, the theme, or a plugin, and leave the user only the options that are relevant to the theme.

I recommend calling it on the hook wp_loaded or init (with a lower priority) so that when it is called, all categories have already been registered.

To see which categories exist, use:

$all_data = \WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered();
print_r( $all_data );

You cannot delete the fallback category “Uncategorized” this way. Patterns from the deleted category are automatically moved to this fallback category.

Use register_block_pattern_category() when you need to add a new category.

No Hooks.

Returns

true|false.

  • true - the block pattern category was successfully removed from the registry.
  • false - a category with that name does not exist, or it cannot be deleted.

Usage

unregister_block_pattern_category( $category_name );
$category_name(string) (required)
The slug (internal name) of a previously registered block pattern category (including the namespace).

Examples

0

#1 We will remove the default block categories

Remove the pattern categories added in the core or registered by the theme.

/**
 * Unregister specific block pattern categories.
 */
add_action( 'wp_loaded', unregister_block_category( ... ) );
function unregister_block_category(): void {
	$disable_cats = [
		'mytheme/landing' => 'Custom category registered in theme',

		'banner'         => 'Bold sections designed to showcase key content.',
		'buttons'        => 'Patterns that contain buttons and call to actions.',
		'columns'        => 'Multi-column patterns with more complex layouts.',
		//'text'           => 'Patterns containing mostly text.',
		//'query'          => 'Display your latest posts in lists, grids or other layouts.',
		//'featured'       => 'A set of high quality curated patterns.',
		'call-to-action' => 'Sections whose purpose is to trigger a specific action.',
		'team'           => 'A variety of designs to display your team members.',
		'testimonials'   => 'Share reviews and feedback about your brand/business.',
		//'services'       => 'Briefly describe what your business does and how you can help.',
		'contact'        => 'Display your contact information.',
		'about'          => 'Introduce yourself.',
		'portfolio'      => 'Showcase your latest work.',
		'gallery'        => 'Different layouts for displaying images.',
		'media'          => 'Different layouts containing video or audio.',
		'videos'         => 'Different layouts containing videos.',
		'audio'          => 'Different layouts containing audio.',
		'posts'          => 'Display your latest posts in lists, grids or other layouts.',
		'footer'         => 'A variety of footer designs displaying information and site navigation.',
		'header'         => 'A variety of header designs displaying your site title and navigation.',
	];

	foreach ( array_keys( $disable_cats ) as $cat_name ) {
		unregister_block_pattern_category( $cat_name );
	}
}

Changelog

Since 5.5.0 Introduced.

unregister_block_pattern_category() code WP 7.0

function unregister_block_pattern_category( $category_name ) {
	return WP_Block_Pattern_Categories_Registry::get_instance()->unregister( $category_name );
}