Using WordPress ‘edit_link_category_form_fields’ PHP action

The edit_link_category_form_fields WordPress PHP action fires after the Edit Link Category form fields are displayed. It helps you to modify or add new fields to the Edit Link Category form.

Usage

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

Parameters

  • $tag (WP_Term): The current link category term object.

More information

See WordPress Developer Resources: edit_link_category_form_fields

Examples

Add a custom field called ‘Custom Field’ to the Edit Link Category form and display its value.

add_action('edit_link_category_form_fields', 'add_custom_field_to_link_category_form');
function add_custom_field_to_link_category_form($tag) {
    $custom_value = get_term_meta($tag->term_id, 'custom_field', true);
    ?>
    <tr class="form-field">
        <th scope="row"><label for="custom_field"><?php _e('Custom Field'); ?></label></th>
        <td><input name="custom_field" id="custom_field" type="text" value="<?php echo esc_attr($custom_value); ?>" /></td>
    </tr>
    <?php
}

Save the custom field value

Save the value of the custom field added in example 1.

add_action('edited_link_category', 'save_custom_field_value', 10, 2);
function save_custom_field_value($term_id) {
    if (isset($_POST['custom_field'])) {
        update_term_meta($term_id, 'custom_field', sanitize_text_field($_POST['custom_field']));
    }
}

Add a custom checkbox called ‘Featured’ to the Edit Link Category form.

add_action('edit_link_category_form_fields', 'add_featured_checkbox_to_link_category_form');
function add_featured_checkbox_to_link_category_form($tag) {
    $is_featured = get_term_meta($tag->term_id, 'is_featured', true);
    ?>
    <tr class="form-field">
        <th scope="row"><label for="is_featured"><?php _e('Featured'); ?></label></th>
        <td><input name="is_featured" id="is_featured" type="checkbox" <?php checked($is_featured, '1'); ?> value="1" /></td>
    </tr>
    <?php
}