Title: WP_HTML_Processor::get_attribute_names_with_prefix
Published: July 16, 2024
Last modified: May 20, 2026

---

# WP_HTML_Processor::get_attribute_names_with_prefix( string $prefix ): array|null

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_html_processor/get_attribute_names_with_prefix/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/classes/wp_html_processor/get_attribute_names_with_prefix/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_html_processor/get_attribute_names_with_prefix/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_html_processor/get_attribute_names_with_prefix/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_html_processor/get_attribute_names_with_prefix/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_html_processor/get_attribute_names_with_prefix/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_html_processor/get_attribute_names_with_prefix/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_html_processor/get_attribute_names_with_prefix/?output_format=md#wp--skip-link--target)

Gets lowercase names of all attributes matching a given prefix in the current tag.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_html_processor/get_attribute_names_with_prefix/?output_format=md#description)󠁿

Note that matching is case-insensitive. This is in accordance with the spec:

> There must never be two or more attributes on the same start tag whose names are
> an ASCII case-insensitive match for each other.
>  * HTML 5 spec

Example:

    ```php
    $p = new WP_HTML_Tag_Processor( '<div data-ENABLED class="test" DATA-test-id="14">Test</div>' );
    $p->next_tag( array( 'class_name' => 'test' ) ) === true;
    $p->get_attribute_names_with_prefix( 'data-' ) === array( 'data-enabled', 'data-test-id' );

    $p->next_tag() === false;
    $p->get_attribute_names_with_prefix( 'data-' ) === null;
    ```

### 󠀁[See also](https://developer.wordpress.org/reference/classes/wp_html_processor/get_attribute_names_with_prefix/?output_format=md#see-also)󠁿

 * [https://html.spec.whatwg.org/multipage/syntax.html#attributes-2:ascii-case-insensitive](https://html.spec.whatwg.org/multipage/syntax.html#attributes-2:ascii-case-insensitive/)

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_html_processor/get_attribute_names_with_prefix/?output_format=md#parameters)󠁿

 `$prefix`stringrequired

Prefix of requested attribute names.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_html_processor/get_attribute_names_with_prefix/?output_format=md#return)󠁿

 array|null List of attribute names, or `null` when no tag opener is matched.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_html_processor/get_attribute_names_with_prefix/?output_format=md#source)󠁿

    ```php
    public function get_attribute_names_with_prefix( $prefix ): ?array {
    	return $this->is_virtual() ? null : parent::get_attribute_names_with_prefix( $prefix );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/html-api/class-wp-html-processor.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/html-api/class-wp-html-processor.php#L5433)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/html-api/class-wp-html-processor.php#L5433-L5435)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_html_processor/get_attribute_names_with_prefix/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_HTML_Tag_Processor::get_attribute_names_with_prefix()](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/get_attribute_names_with_prefix/)`wp-includes/html-api/class-wp-html-tag-processor.php` |

Gets lowercase names of all attributes matching a given prefix in the current tag.

  |

| Used by | Description | 
| [WP_HTML_Processor::serialize_token()](https://developer.wordpress.org/reference/classes/wp_html_processor/serialize_token/)`wp-includes/html-api/class-wp-html-processor.php` |

Serializes the currently-matched token.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_html_processor/get_attribute_names_with_prefix/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.6.0](https://developer.wordpress.org/reference/since/6.6.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_html_processor%2Fget_attribute_names_with_prefix%2F)
before being able to contribute a note or feedback.