The pre_ent2ncr filter allows you to modify text before named entities are converted into numbered entities in WordPress.
Usage
add_filter('pre_ent2ncr', 'your_custom_function', 10, 2); function your_custom_function($converted_text, $text) { // your custom code here return $converted_text; }
Parameters
$converted_text
(string|null) – The text that has been converted. Default is null.$text
(string) – The original text before the entity conversion.
More information
See WordPress Developer Resources: https://developer.wordpress.org/reference/hooks/pre_ent2ncr/
Examples
Replace ampersand with ‘and’
Replace ampersands with the word ‘and’ before entity conversion.
add_filter('pre_ent2ncr', 'replace_ampersand', 10, 2); function replace_ampersand($converted_text, $text) { $new_text = str_replace('&', 'and', $text); return $new_text; }
Remove HTML tags
Strip HTML tags from the text before entity conversion.
add_filter('pre_ent2ncr', 'remove_html_tags', 10, 2); function remove_html_tags($converted_text, $text) { $new_text = strip_tags($text); return $new_text; }
Convert text to uppercase
Change the text to uppercase before entity conversion.
add_filter('pre_ent2ncr', 'convert_to_uppercase', 10, 2); function convert_to_uppercase($converted_text, $text) { $new_text = strtoupper($text); return $new_text; }
Add prefix to text
Add a prefix to the text before entity conversion.
add_filter('pre_ent2ncr', 'add_prefix', 10, 2); function add_prefix($converted_text, $text) { $new_text = 'Prefix: ' . $text; return $new_text; }
Replace line breaks with spaces
Replace line breaks with spaces before entity conversion.
add_filter('pre_ent2ncr', 'replace_line_breaks', 10, 2);
function replace_line_breaks($converted_text, $text) {
$new_text = str_replace(array(“\r\n”, “\r”, “\n”), ‘ ‘, $text);
return $new_text;
}