wp-includes/html-api/class-wp-html-processor.php:5322Updates or creates a new attribute on the currently matched tag with the passed value.
<abbr title="Eggs &amp; Milk">.
$processor->set_attribute( 'title', 'Eggs & Milk' );
// Renders “Eggs &amp; Milk” in a browser, encoded as <abbr title="Eggs &amp;amp; Milk">.
$processor->set_attribute( 'title', 'Eggs &amp; Milk' );
// Renders true as <abbr title>.
$processor->set_attribute( 'title', true );
// Renders without the attribute for false as <abbr>.
$processor->set_attribute( 'title', false ); Special handling is provided for boolean attribute values: <ul> <li>When true is passed as the value, then only the attribute name is added to the tag.</li> <li>When false is passed, the attribute gets removed if it existed before.</li> </ul>$namestring$valuestring|boolbool public function set_attribute( $name, $value ): bool { return $this->is_virtual() ? false : parent::set_attribute( $name, $value ); }Introduced in 6.9.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
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.