The edit_term_{$field} WordPress PHP filter allows you to modify a term field before it is sanitized.
Usage
add_filter( 'edit_term_{field}', 'your_custom_function', 10, 3 );
function your_custom_function( $value, $term_id, $taxonomy ) {
// your custom code here
return $value;
}
Parameters
- $value (mixed) – Value of the term field.
- $term_id (int) – Term ID.
- $taxonomy (string) – Taxonomy slug.
More information
See WordPress Developer Resources: edit_term_{$field}
Examples
Change term name
Modify the term name before it is sanitized.
add_filter( 'edit_term_name', 'change_term_name', 10, 3 );
function change_term_name( $value, $term_id, $taxonomy ) {
// Add " - Modified" to the term name
$value .= ' - Modified';
return $value;
}
Capitalize term description
Capitalize the first letter of the term description.
add_filter( 'edit_term_description', 'capitalize_term_description', 10, 3 );
function capitalize_term_description( $value, $term_id, $taxonomy ) {
// Capitalize first letter of the term description
$value = ucfirst( $value );
return $value;
}
Sanitize term slug
Sanitize term slug by replacing spaces with dashes.
add_filter( 'edit_term_slug', 'sanitize_term_slug', 10, 3 );
function sanitize_term_slug( $value, $term_id, $taxonomy ) {
// Replace spaces with dashes
$value = str_replace( ' ', '-', $value );
return $value;
}
Append prefix to term name
Add a prefix to the term name.
add_filter( 'edit_term_name', 'prefix_term_name', 10, 3 );
function prefix_term_name( $value, $term_id, $taxonomy ) {
// Add "Prefix - " to the term name
$value = 'Prefix - ' . $value;
return $value;
}
Remove HTML tags from term description
Strip HTML tags from the term description.
add_filter( 'edit_term_description', 'remove_html_tags_term_description', 10, 3 );
function remove_html_tags_term_description( $value, $term_id, $taxonomy ) {
// Remove HTML tags from the term description
$value = strip_tags( $value );
return $value;
}