This method assumes that the given HTML snippet is found in BODY context.For normalizing full documents or fragments found in other contexts, create a new processor using WP_HTML_Processor::create_fragment or WP_HTML_Processor::create_full_parser and call WP_HTML_Processor::serialize on the created instances. Many aspects of an input HTML fragment may be changed during normalization. <ul> <li>Attribute values will be double-quoted.</li> <li>Duplicate attributes will be removed.</li> <li>Omitted tags will be added.</li> <li>Tag and attribute name casing will be lower-cased, except for specific SVG and MathML tags or attributes.</li> <li>Text will be re-encoded, null bytes handled, and invalid UTF-8 replaced with U+FFFD.</li> <li>Any incomplete syntax trailing at the end will be omitted, for example, an unclosed comment opener will be removed.</li> </ul> Example: echo WP_HTML_Processor::normalize( '<a href=#anchor v=5 href="/" enabled>One</a another v=5><!--' );
// <a href="#anchor" v="5" enabled>One</a>
echo WP_HTML_Processor::normalize( '<div></p>fun<table><td>cell</div>' );
// <div><p></p>fun<table><tbody><tr><td>cell</td></tr></tbody></table></div>
echo WP_HTML_Processor::normalize( '<![CDATA[invalid comment]]> syntax < <> "oddities"' );
// <!--[CDATA[invalid comment]]--> syntax &lt; &lt;&gt; &quot;oddities&quot;
Parameters
$htmlstring
Input HTML to normalize.
Return
string|null
Normalized output, or null if unable to normalize.
Signature, return type and hooks compared across 5 parsed releases.
About this page
Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-includes/html-api/class-wp-html-processor.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.