Many times we need to add extra fields to the categories in WordPress, mainly to customize the category.php template or to handle new data related to the category such as images, styles and even html content.
The default wordpress categories come like this, with only four fields (name, slug, parent category and description).
How to add other custom fields in WordPress?
Here is how we have added three more fields to the categories. How?
Step # 1
First we must add the edit_category_form_fields hook that allows us to modify the category view to add new html elements such as textfield, buttons, texarea and others.
Step # 2
In this step, basically what we do is save the information in the wordpress database, specifically in the wp_options table, the hook edited_category is used for this.
Step # 3
The last step is to use the values, as I said at the beginning, mostly these values are used to extend the view of the category template category.php, such as defining a main image for each category.
There are several plugins in wordpress to add extra fields to the categories, but this could pose some problems such as: performance, illegibility of the code and even full and unreadable wordpress interface with more menu and visual elements. If you are creating a theme from the beginning, you will want to depend as little as possible that your theme requires other plugins for proper operation, which is why adding the fields in this way makes our site simpler.