Using WordPress ‘add_tag_form_fields’ PHP action

The add_tag_form_fields WordPress PHP action hook allows you to add custom fields to the Add Tag form for non-hierarchical taxonomies.

Usage

add_action('add_tag_form_fields', 'your_custom_function');
function your_custom_function() {
    // your custom code here
}

Parameters

  • None

More information

See WordPress Developer Resources: add_tag_form_fields

Examples

Adding a custom text input field

Add a custom text input field to the Add Tag form:

add_action('add_tag_form_fields', 'add_custom_text_input');
function add_custom_text_input() {
    echo '<div class="form-field">';
    echo '<label for="custom_field">Custom Field</label>';
    echo '<input type="text" id="custom_field" name="custom_field" />';
    echo '</div>';
}

Adding a custom checkbox

Add a custom checkbox to the Add Tag form:

add_action('add_tag_form_fields', 'add_custom_checkbox');
function add_custom_checkbox() {
    echo '<div class="form-field">';
    echo '<label for="custom_checkbox">Custom Checkbox</label>';
    echo '<input type="checkbox" id="custom_checkbox" name="custom_checkbox" />';
    echo '</div>';
}

Adding a custom dropdown menu

Add a custom dropdown menu to the Add Tag form:

add_action('add_tag_form_fields', 'add_custom_dropdown');
function add_custom_dropdown() {
    echo '<div class="form-field">';
    echo '<label for="custom_dropdown">Custom Dropdown</label>';
    echo '<select id="custom_dropdown" name="custom_dropdown">';
    echo '<option value="option1">Option 1</option>';
    echo '<option value="option2">Option 2</option>';
    echo '</select>';
    echo '</div>';
}

Adding a custom radio button group

Add a custom radio button group to the Add Tag form:

add_action('add_tag_form_fields', 'add_custom_radio_buttons');
function add_custom_radio_buttons() {
    echo '<div class="form-field">';
    echo '<label>Custom Radio Buttons</label>';
    echo '<input type="radio" id="radio1" name="custom_radio" value="option1" />';
    echo '<label for="radio1">Option 1</label><br />';
    echo '<input type="radio" id="radio2" name="custom_radio" value="option2" />';
    echo '<label for="radio2">Option 2</label>';
    echo '</div>';
}

Adding custom text and HTML

Add custom text and HTML to the Add Tag form:

add_action('add_tag_form_fields', 'add_custom_text_and_html');
function add_custom_text_and_html() {
    echo '<div class="form-field">';
    echo '<p>Custom Text and HTML</p>';
    echo '<strong>This is a bold text.</strong>';
    echo '</div>';
}

Add a custom field to the Add Tag form

Add a custom text input field to the Add Tag form for a specific taxonomy.

add_action('add_tag_form_fields', 'add_custom_field_to_tag_form', 10, 1);

function add_custom_field_to_tag_form($taxonomy) {
    if ('your_taxonomy' === $taxonomy) {
        echo '<div class="form-field">';
        echo '<label for="custom_field">Custom Field</label>';
        echo '<input type="text" name="custom_field" id="custom_field" />';
        echo '</div>';
    }
}

Add a custom checkbox to the Add Tag form

Add a custom checkbox field to the Add Tag form for a specific taxonomy.

add_action('add_tag_form_fields', 'add_custom_checkbox_to_tag_form', 10, 1);

function add_custom_checkbox_to_tag_form($taxonomy) {
    if ('your_taxonomy' === $taxonomy) {
        echo '<div class="form-field">';
        echo '<label for="custom_checkbox">Custom Checkbox</label>';
        echo '<input type="checkbox" name="custom_checkbox" id="custom_checkbox" />';
        echo '</div>';
    }
}

Add a custom select field to the Add Tag form

Add a custom select field to the Add Tag form for a specific taxonomy.

add_action('add_tag_form_fields', 'add_custom_select_to_tag_form', 10, 1);

function add_custom_select_to_tag_form($taxonomy) {
    if ('your_taxonomy' === $taxonomy) {
        echo '<div class="form-field">';
        echo '<label for="custom_select">Custom Select</label>';
        echo '<select name="custom_select" id="custom_select">';
        echo '<option value="option1">Option 1</option>';
        echo '<option value="option2">Option 2</option>';
        echo '</select>';
        echo '</div>';
    }
}

Add a custom textarea to the Add Tag form

Add a custom textarea field to the Add Tag form for a specific taxonomy.

add_action('add_tag_form_fields', 'add_custom_textarea_to_tag_form', 10, 1);

function add_custom_textarea_to_tag_form($taxonomy) {
    if ('your_taxonomy' === $taxonomy) {
        echo '<div class="form-field">';
        echo '<label for="custom_textarea">Custom Textarea</label>';
        echo '<textarea name="custom_textarea" id="custom_textarea"></textarea>';
        echo '</div>';
    }
}