WP_HTML_Processor::get_attribute()
Returns the value of a requested attribute from a matched tag opener if that attribute exists.
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;
Method of the class: WP_HTML_Processor{}
No Hooks.
Return
String|true|null
. Value of attribute or null if not available. Boolean attributes return true.
Usage
$WP_HTML_Processor = new WP_HTML_Processor(); $WP_HTML_Processor->get_attribute( $name );
- $name(string) (required)
- Name of attribute whose value is requested.
Changelog
Since 6.6.0 | Introduced. |
Since 6.6.0 | Subclassed for HTML Processor. |
WP_HTML_Processor::get_attribute() WP HTML Processor::get attribute code WP 6.6.2
public function get_attribute( $name ) { return $this->is_virtual() ? null : parent::get_attribute( $name ); }