Using WordPress ‘get_edit_term_link’ PHP filter

The get_edit_term_link WordPress PHP filter allows you to modify the edit link for a term.

Usage

add_filter('get_edit_term_link', 'your_custom_function', 10, 4);
function your_custom_function($location, $term_id, $taxonomy, $object_type) {
    // your custom code here
    return $location;
}

Parameters

  • $location (string) – The edit link.
  • $term_id (int) – Term ID.
  • $taxonomy (string) – Taxonomy name.
  • $object_type (string) – The object type.

More information

See WordPress Developer Resources: get_edit_term_link

Examples

This example modifies the edit term link to a custom URL.

add_filter('get_edit_term_link', 'change_edit_term_link', 10, 4);
function change_edit_term_link($location, $term_id, $taxonomy, $object_type) {
    $location = 'https://your-custom-url.com/edit-term/' . $term_id;
    return $location;
}

This example adds a query parameter to the edit term link.

add_filter('get_edit_term_link', 'add_query_param_to_edit_term_link', 10, 4);
function add_query_param_to_edit_term_link($location, $term_id, $taxonomy, $object_type) {
    $location = add_query_arg('extra_param', 'value', $location);
    return $location;
}

This example removes the edit term link for a specific taxonomy.

add_filter('get_edit_term_link', 'remove_edit_link_for_specific_taxonomy', 10, 4);
function remove_edit_link_for_specific_taxonomy($location, $term_id, $taxonomy, $object_type) {
    if ($taxonomy == 'your_taxonomy') {
        return '';
    }
    return $location;
}

This example changes the edit term link based on the current user’s role.

add_filter('get_edit_term_link', 'change_edit_link_based_on_user_role', 10, 4);
function change_edit_link_based_on_user_role($location, $term_id, $taxonomy, $object_type) {
    $current_user = wp_get_current_user();
    if (in_array('editor', $current_user->roles)) {
        $location = 'https://your-custom-url.com/editor-edit-term/' . $term_id;
    }
    return $location;
}

This example appends the term name to the edit term link.

add_filter('get_edit_term_link', 'append_term_name_to_edit_link', 10, 4);
function append_term_name_to_edit_link($location, $term_id, $taxonomy, $object_type) {
    $term = get_term($term_id, $taxonomy);
    $location .= '&term_name=' . urlencode($term->name);
    return $location;
}