Using WordPress ‘edit_tag_form’ PHP action

The edit_tag_form WordPress PHP action fires at the end of the Edit Term form, allowing you to add custom fields or modify the form’s appearance.

Usage

add_action('edit_tag_form', 'your_custom_function');
function your_custom_function($tag) {
    // your custom code here
}

Parameters

  • $tag (WP_Term): Current taxonomy term object.

More information

See WordPress Developer Resources: edit_tag_form

Examples

Adding a custom field to the edit term form

This example adds a custom field for storing extra information about the term:

add_action('edit_tag_form', 'add_custom_field_to_edit_term_form');
function add_custom_field_to_edit_term_form($tag) {
    $extra_info = get_term_meta($tag->term_id, 'extra_info', true);
    ?>
    <tr class="form-field">
        <th scope="row" valign="top"><label for="extra_info">Extra Info</label></th>
        <td><input name="extra_info" id="extra_info" type="text" value="<?php echo esc_attr($extra_info); ?>" size="40" />
        <p class="description">Enter some extra information for this term.</p></td>
    </tr>
    <?php
}

Changing the submit button text

This example changes the submit button text on the edit term form:

add_action('edit_tag_form', 'change_submit_button_text');
function change_submit_button_text($tag) {
    ?>
    <script>
        document.getElementById('submit').value = 'Save Changes';
    </script>
    <?php
}

Hiding a specific field on the edit term form

This example hides the “slug” field on the edit term form:

add_action('edit_tag_form', 'hide_slug_field');
function hide_slug_field($tag) {
    ?>
    <style>
        .form-field.term-slug-wrap { display: none; }
    </style>
    <?php
}

Adding a custom message at the end of the edit term form

This example adds a custom message at the end of the edit term form:

add_action('edit_tag_form', 'add_custom_message');
function add_custom_message($tag) {
    ?>
    <p><strong>Note:</strong> Custom message at the end of the form.</p>
    <?php
}

Adding a custom CSS class to the edit term form

This example adds a custom CSS class to the edit term form:

add_action('edit_tag_form', 'add_custom_css_class');
function add_custom_css_class($tag) {
    ?>
    <script>
        document.getElementById('edittag').classList.add('custom-css-class');
    </script>
    <?php
}