MENU

Add Custom Categories to Oxygen Blocks

August 3, 2021
Posted in: ,

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.

Tutorial written by Soph Simmonds
Director & Web Developer at WinuSoft Web Design & Senior Support Specialist at Oxygen. When she's not working, Soph can usually be found mountain biking with her partner, Luis.

Get in Touch

Contact us about any web, design or branding project that you have in mind. We're sure that you'll find our approach and dedication will be just what you need.

We’re always happy to discuss your project with you. Just fill out the form or give us a call to get started.
info@winusoft.co.uk
07889 216767
winusoft.co.uk
facebook-squarelinkedin-squaregithub-squaretwitterfacebookenvelopelinkedinxinginstagrampaper-planepinterest-pwhatsappcommentinghomemagic-wandcloud-uploaddatabaseenvelopeeyefile-addgraduation-hatpicturebooksmartphonemenuchevron-down