diff --git a/wp-includes/html-api/class-wp-html-processor.php b/wp-includes/html-api/class-wp-html-processor.php
index cbf1dc6336..588d2fbe7d 100644
--- a/wp-includes/html-api/class-wp-html-processor.php
+++ b/wp-includes/html-api/class-wp-html-processor.php
@@ -466,6 +466,10 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
continue;
}
+ if ( isset( $query['tag_name'] ) && $query['tag_name'] !== $this->get_token_name() ) {
+ continue;
+ }
+
if ( isset( $needs_class ) && ! $this->has_class( $needs_class ) ) {
continue;
}
diff --git a/wp-includes/version.php b/wp-includes/version.php
index fed502578b..9c2df13cf3 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '6.7-alpha-58680';
+$wp_version = '6.7-alpha-58681';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.