The edit_{$taxonomy}_{$field} WordPress PHP filter allows you to modify the taxonomy field before it is sanitized. The dynamic portions of the filter name, $taxonomy
and $field
, represent the taxonomy slug and taxonomy field respectively.
Usage
add_filter('edit_{$taxonomy}_{$field}', 'my_custom_function', 10, 2); function my_custom_function($value, $term_id) { // Your custom code here return $value; }
Parameters
$value
(mixed): The value of the taxonomy field to edit.$term_id
(int): The term ID.
More information
See WordPress Developer Resources: edit_{$taxonomy}_{$field}
Examples
Change the Category Description
Modify the category description before it’s sanitized:
add_filter('edit_category_description', 'my_custom_category_description', 10, 2); function my_custom_category_description($value, $term_id) { $value = strtoupper($value); return $value; }
Add a Prefix to Tag Name
Add a prefix to the tag name before it’s sanitized:
add_filter('edit_post_tag_name', 'my_custom_tag_name', 10, 2); function my_custom_tag_name($value, $term_id) { $value = 'Tag: ' . $value; return $value; }
Modify Custom Taxonomy Slug
Modify the slug of a custom taxonomy called ‘location’ before it’s sanitized:
add_filter('edit_location_slug', 'my_custom_location_slug', 10, 2); function my_custom_location_slug($value, $term_id) { $value = 'loc-' . $value; return $value; }
Remove HTML Tags from Custom Taxonomy Description
Remove HTML tags from a custom taxonomy called ‘color’ description before it’s sanitized:
add_filter('edit_color_description', 'my_custom_color_description', 10, 2); function my_custom_color_description($value, $term_id) { $value = strip_tags($value); return $value; }
Modify Category Parent
Modify the parent of a category before it’s sanitized:
add_filter('edit_category_parent', 'my_custom_category_parent', 10, 2); function my_custom_category_parent($value, $term_id) { if ($value == 1) { $value = 2; } return $value; }