Using WordPress ‘edit_term_link’ PHP filter

The edit_term_link WordPress PHP filter allows you to modify the anchor tag for the edit link of a term.

Usage

add_filter('edit_term_link', 'my_custom_edit_term_link', 10, 2);
function my_custom_edit_term_link($link, $term_id) {
    // your custom code here
    return $link;
}

Parameters

  • $link (string) – The anchor tag for the edit link.
  • $term_id (int) – Term ID.

More information

See WordPress Developer Resources: edit_term_link

Examples

In this example, we’ll add a custom class to the edit term link.

add_filter('edit_term_link', 'add_custom_class_to_edit_link', 10, 2);
function add_custom_class_to_edit_link($link, $term_id) {
    // Adding the custom class
    $link = str_replace('<a ', '<a class="my-custom-class" ', $link);
    return $link;
}

In this example, we’ll change the text of the edit term link.

add_filter('edit_term_link', 'change_edit_link_text', 10, 2);
function change_edit_link_text($link, $term_id) {
    // Changing the link text
    $link = str_replace('>Edit<', '>Modify<', $link);
    return $link;
}

In this example, we’ll make the edit term link open in a new tab.

add_filter('edit_term_link', 'open_edit_link_new_tab', 10, 2);
function open_edit_link_new_tab($link, $term_id) {
    // Adding target="_blank" attribute
    $link = str_replace('<a ', '<a target="_blank" ', $link);
    return $link;
}

In this example, we’ll remove the edit term link entirely.

add_filter('edit_term_link', '__return_empty_string', 10, 2);

In this example, we’ll add a custom data attribute to the edit term link.

add_filter('edit_term_link', 'add_custom_data_attribute', 10, 2);
function add_custom_data_attribute($link, $term_id) {
    // Adding the custom data attribute
    $link = str_replace('<a ', '<a data-custom-attr="custom-value" ', $link);
    return $link;
}