Using WordPress ‘no_texturize_tags’ PHP filter

The no_texturize_tags WordPress PHP filter allows you to modify the list of HTML elements that should not be texturized by WordPress.

Usage

add_filter( 'no_texturize_tags', 'your_custom_function' );

function your_custom_function( $default_no_texturize_tags ) {
    // Your custom code here
    return $default_no_texturize_tags;
}

Parameters

  • $default_no_texturize_tags (string[]): An array of HTML element names.

More information

See WordPress Developer Resources: no_texturize_tags

Examples

Prevent texturizing code elements

To prevent texturizing the content inside <code> elements, add ‘code’ to the array.

function prevent_code_texturize( $default_no_texturize_tags ) {
    $default_no_texturize_tags[] = 'code';
    return $default_no_texturize_tags;
}
add_filter( 'no_texturize_tags', 'prevent_code_texturize' );

Prevent texturizing pre elements

To prevent texturizing the content inside <pre> elements, add ‘pre’ to the array.

function prevent_pre_texturize( $default_no_texturize_tags ) {
    $default_no_texturize_tags[] = 'pre';
    return $default_no_texturize_tags;
}
add_filter( 'no_texturize_tags', 'prevent_pre_texturize' );

Prevent texturizing multiple elements

To prevent texturizing the content inside multiple elements, add them to the array.

function prevent_multiple_texturize( $default_no_texturize_tags ) {
    $new_elements = array( 'samp', 'kbd' );
    $default_no_texturize_tags = array_merge( $default_no_texturize_tags, $new_elements );
    return $default_no_texturize_tags;
}
add_filter( 'no_texturize_tags', 'prevent_multiple_texturize' );

Replace the default array

To replace the default array with a custom list of elements, return the new array.

function replace_default_no_texturize( $default_no_texturize_tags ) {
    $custom_elements = array( 'samp', 'kbd' );
    return $custom_elements;
}
add_filter( 'no_texturize_tags', 'replace_default_no_texturize' );

Clear the array

To allow texturizing for all elements, return an empty array.

function clear_no_texturize_tags( $default_no_texturize_tags ) {
    return array();
}
add_filter( 'no_texturize_tags', 'clear_no_texturize_tags' );