WP_HTML_Processor::get_attribute( string $name ): string|true|null

In this article

Returns the value of a requested attribute from a matched tag opener if that attribute exists.

Description

Example:

$p = WP_HTML_Processor::create_fragment( '<div enabled class="test" data-test-id="14">Test</div>' );
$p->next_token() === true;
$p->get_attribute( 'data-test-id' ) === '14';
$p->get_attribute( 'enabled' ) === true;
$p->get_attribute( 'aria-label' ) === null;

$p->next_tag() === false;
$p->get_attribute( 'class' ) === null;

Parameters

$namestringrequired
Name of attribute whose value is requested.

Return

string|true|null Value of attribute or null if not available. Boolean attributes return true.

Source

/*
 * > A start tag whose tag name is "noscript", if the scripting flag is disabled
 */

Changelog

VersionDescription
6.6.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.