Adding Fields to the Category, Tag and Custom Taxonomy Edit Screen in the WordPress Admin?

The question is “How do I add one or more fields to the Category, Tag and Custom Taxonomy Edit Screen in the WordPress Admin?” This question was asked on the wp-hackers list August 1st 2010 and I offered a solution later that day. The original asker discussed the issue again today (Aug 21) which reminded me of the solution. Since it could be a common need I decided to post the solution including code up here for others to find in the future.

Solutions Collecting From Web of "Adding Fields to the Category, Tag and Custom Taxonomy Edit Screen in the WordPress Admin?"

I added new field ‘picture’ (input type file) to category with help of these

add_action('category_edit_form_fields','category_edit_form_fields');
add_action('category_edit_form', 'category_edit_form');
add_action('category_add_form_fields','category_edit_form_fields');
add_action('category_add_form','category_edit_form');


function category_edit_form() {
?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#edittag').attr( "enctype", "multipart/form-data" ).attr( "encoding", "multipart/form-data" );
        });
</script>
<?php 
}

function category_edit_form_fields () {
?>
    <tr class="form-field">
            <th valign="top" scope="row">
                <label for="catpic"><?php _e('Picture of the category', ''); ?></label>
            </th>
            <td>
                <input type="file" id="catpic" name="catpic"/>
            </td>
        </tr>
        <?php 
    }

You are free to use any taxonomy, just replace category to your taxonomy name

Also, if you want to add that field into the custom taxonomy form you just substitute category with the custom taxonomy name in the add_action function.

Example:

add_action('{custom_taxonomy}_edit_form_fields','category_edit_form_fields');
add_action('{custom_taxonomy}_edit_form', 'category_edit_form');
add_action('{custom_taxonomy}_add_form_fields','category_edit_form_fields');
add_action('{custom_taxonomy}_add_form','category_edit_form');

For those looking to hook into the tag form field, the hook is slightly different.

add_tag_form_fields

instead of tag_add_form_fields as you would expect

I realize this was asked a while ago, but WordPress has changed a bit since so I decided to develop a small script that simplifies the process of adding custom fields to taxonomies, and optionally lets you add columns to the terms table for each field. The script is called amarkal-taxonomy, and is part of the Amarkal WordPress framework.

Using amarkal-taxonomy, adding a custom field simplifies to:

// Add a text field to the 'category' taxonomy 'add' & 'edit' forms:
amarkal_taxonomy_add_field('category', 'cat_icon', array(
    'type'        => 'text',
    'label'       => 'Icon',
    'description' => 'The category\'s icon',
    'table'       => array(
        'show'      => true,  // Add a column to the terms table
        'sortable'  => true   // Make that column sortable
    )
));

// Then you can retrieve the data using:
$icon = get_term_meta( $term_id, 'cat_icon', true );

You need to add your code in to your themes functions.php file – also if you want to add that field into the custom taxonomy form you just substitute category with the custom taxonomy name in the add_action function.
Example :
add_action(‘category_edit_form_fields’,’category_edit_form_fields’);
will be
add_action(‘custom_taxonomy_name_form_fields’,’function_name_to_hook_on’);

I use the Category Meta PLugin. Works on all custom taxonomy’s, tags & categorys