Sometimes you need to extend functionality of Magento 2 categories. In this article I would like to show you how to add a new custom category attribute. Let’s say, this attribute is needed to display/hide some content on the category page.

Now let’s write our installation script under Setup folder. I’ve included comments within to guide you along. Note that the custom variable I’m adding is called hide_this_category. This attribute will be used for hide particular category from menu.

In this case I’ve added a Boolean field that will be stored in used as Yes/No, but you can change this according to your requirement.

Lets check code to add custom category attribute.

Please setup this installation script with your extension and run upgrade command via command line. If things didn’t work out, check to see if the installation script actually ran and make sure that you cleared your cache and double-check your installation script filename, path and version number with Magento 2 extension structure.

Enjoy Cool stuff with Magewallet!!

Mahendra Paladiya
Mahendra is a Web Developer whose passions includes web development, technical blog writing, and database management. His passion for web development pushed him into learning how to handle different platforms like Core PHP, Magento, Prestashop, WordPress, CodeIgniter, CakePHP and Oracle.