The edit_tag_link WordPress PHP filter allows you to customize the anchor tag for the edit link of a tag or term in another taxonomy.
Usage
add_filter('edit_tag_link', 'your_custom_function', 10, 1);
function your_custom_function($link) {
// your custom code here
return $link;
}
Parameters
$link(string): The anchor tag for the edit link.
More information
See WordPress Developer Resources: edit_tag_link
Examples
Add a custom class to the edit link
Customize the edit link by adding a custom CSS class:
add_filter('edit_tag_link', 'add_custom_class_to_edit_link', 10, 1);
function add_custom_class_to_edit_link($link) {
$link = str_replace('<a ', '<a class="custom-edit-class" ', $link);
return $link;
}
Change the edit link text
Modify the text of the edit link:
add_filter('edit_tag_link', 'change_edit_link_text', 10, 1);
function change_edit_link_text($link) {
$link = preg_replace('/>.*?</', '>Edit This Term<', $link);
return $link;
}
Add an icon to the edit link
Add a font awesome icon to the edit link:
add_filter('edit_tag_link', 'add_icon_to_edit_link', 10, 1);
function add_icon_to_edit_link($link) {
$icon = '<i class="fas fa-pencil-alt"></i> ';
$link = preg_replace('/>(.*?)</', '>' . $icon . '$1<', $link);
return $link;
}
Open edit link in a new tab
Make the edit link open in a new tab:
add_filter('edit_tag_link', 'open_edit_link_new_tab', 10, 1);
function open_edit_link_new_tab($link) {
$link = str_replace('<a ', '<a target="_blank" ', $link);
return $link;
}
Add a custom attribute to the edit link
Add a custom HTML attribute to the edit link:
add_filter('edit_tag_link', 'add_custom_attribute_to_edit_link', 10, 1);
function add_custom_attribute_to_edit_link($link) {
$link = str_replace('<a ', '<a data-custom-attribute="example" ', $link);
return $link;
}