tag_escape()
Escape an HTML tag name.
1 time — 0.000001 sec (speed of light) | 50000 times — 0.05 sec (speed of light) | PHP 7.2.16, WP 5.2
Hooks from the function
Return
String
.
Usage
tag_escape( $tag_name );
- $tag_name(string) (required)
- -
Examples
#1 Check the HTML tag name
echo tag_escape( '#1 I! Love this WORLD $@#%#$' ); // 1ilovethisworld echo tag_escape( 'DIV' ); // div echo tag_escape( '<div>' ); // div
Changelog
Since 2.5.0 | Introduced. |
Since 6.5.5 | Allow hyphens in tag names (i.e. custom elements). |
tag_escape() tag escape code WP 6.6.2
function tag_escape( $tag_name ) { $safe_tag = strtolower( preg_replace( '/[^a-zA-Z0-9-_:]/', '', $tag_name ) ); /** * Filters a string cleaned and escaped for output as an HTML tag. * * @since 2.8.0 * * @param string $safe_tag The tag name after it has been escaped. * @param string $tag_name The text before it was escaped. */ return apply_filters( 'tag_escape', $safe_tag, $tag_name ); }