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
Add a custom class to the edit link
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;
}
Change the edit link text
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;
}
Open edit term link in a new tab
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;
}
Remove the edit term link
In this example, we’ll remove the edit term link entirely.
add_filter('edit_term_link', '__return_empty_string', 10, 2);
Add a custom data attribute to the edit link
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;
}