Magento 2.1 – Adding custom attribute to category

In Magento it’s pretty easy to create custom attributes for products, but it’s less so for categories. As with many things in Magento2, the general best practice is to create a custom module for it. Note: This guide is for version 2.1 and up, because since 2.1 a lot of the infrastructure regarding this functionality has changed (I found out when suddenly everything broke).

First the basic module stuff;

..and then the registration;

And now for the attribute registration. In this case it's a textfield to load a URL to a image, which will be used next to the default category image.

And lastly we'll have to add some XML to show the field in the admin:

Now run the magento setup:upgrade command, clean the cache and navigate to a category in your adminpanel, at the bottom it should be visible.

Note: It's necessary that the field name in the XML matches the value of the attribute added in the InstallData (cat_bgimg in this example).