Add Custom Field to Category and Taxonomies

Add Custom Field to Category and Taxonomies

There were some general fields for each taxonomy(Category, Tag, etc): name, slug, parent and description.

Now and then we’ll feel the need to add a custom field. In a recent a project I am working on, the client want to display the category with an image that he can select from the backend.

There is already a plugin can help this, Categories Images is a good one you can download free from WordPress plugin repository.

Adding custom fields to taxonomy includes 3 steps: adding the field to the Add New term page, adding the field to the Edit term page, saving the custom field value.

Take my mentioned project as an example.

Snippet 1: adding the field to the Add New term page

category_add_form_fields is the action we hook into. This parameter is what determines the taxonomy that this field gets added to category. It uses this format: {$taxonomy_name}_add_form_fields. So if you wanted to add the field to your “genres” taxonomy, you would use: genres_add_form_fields

Snippet 2: adding the field to the Edit term page

Snippet 3: saving the custom field value

That’s it! The process is really pretty simple.

Usage is as following example.



Author: Leo

My name is Leo who’s behind this blog. I’ve been working with wordpress since 2010. I’ll write about themes, plugins, tutorials and all about wordpress here. Hope you find it useful!

3 thoughts on “Add Custom Field to Category and Taxonomies”

  1. This would be so much easier if WordPress included custom fields on edit category pages.

    Couldn’t you somehow hijack the custom fields native to WordPress for the input rather than having to add new code?

Leave a Reply

Your email address will not be published. Required fields are marked *