Add Custom Categories to Oxygen Blocks

Add Custom Categories to Oxygen Blocks

Oxygen has a number of built-in categories that can be used for the items you create in the Block Library. However, you may find that you want to create additional categories for those blocks so that you can select from those categories when adding a block via the Design Library.

This is possible with a PHP snippet, so the first thing to do is to install the snippets plugin of your choice, such as Advanced Scripts (paid) or Code Snippets (free).

Once you’ve installed the plugin, create a snippet with the following code:

add_action('plugins_loaded', 'oxygen_custom_block_categories');

function oxygen_custom_block_categories() {
    global $ct_component_categories;
	$new_categories =  array(
        'Portfolio',
        'Products',
        'Gutenberg',
        'Features',
        'Menus',
        'Team',
    );

	$ct_component_categories = array_merge($ct_component_categories, $new_categories);

	sort($ct_component_categories);

}

You can replace the categories on lines #6 to #11 with your own categories as well as adding new lines so that you can create as many categories as you wish.

A small bonus is that the categories will be displayed in alphabetical order, which is what the “sort” code does on line #16. If you want the categories to remain in the normal order, you can delete that line.