Title: WP_HTML_Tag_Processor::parse_query
Published: March 29, 2023
Last modified: February 24, 2026

---

# WP_HTML_Tag_Processor::parse_query( array|string|null $query )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/parse_query/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/parse_query/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/parse_query/?output_format=md#changelog)

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

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Parses tag query input into internal search criteria.

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

 `$query`array|string|nulloptional

Which tag name to find, having which class, etc. Default is to find any tag.

 * `tag_name` string|null
 * Which tag to find, or `null` for "any tag."
 * `match_offset` int|null
 * Find the Nth tag matching all search criteria.
    1 for "first" tag, 3 for "third,"
   etc. Defaults to first tag.
 * `class_name` string|null
 * Tag must contain this class name to match.
 * `tag_closers` string
 * "visit" or "skip": whether to stop on tag closers, e.g. </div>.

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

    ```php
    		case 'module':
    			return 'javascript';

    		/*
    		 * > Otherwise, if the script block's type string is an ASCII case-insensitive match for the string "importmap", then set el's type to "importmap".
    		 * > Otherwise, if the script block's type string is an ASCII case-insensitive match for the string "speculationrules", then set el's type to "speculationrules".
    		 *
    		 * These conditions indicate JSON content.
    		 */
    		case 'importmap':
    		case 'speculationrules':
    			return 'json';

    		/** @todo Rely on a full MIME parser for determining JSON content. */
    		case 'application/json':
    		case 'text/json':
    			return 'json';
    	}

    	/*
    	 * > Otherwise, return. (No script is executed, and el's type is left as null.)
    	 */
    	return null;
    }

    /**
     * Escape JavaScript and JSON script tag contents.
     *
     * Ensure that the script contents cannot modify the HTML structure or break out
     * of its containing SCRIPT element. JavaScript and JSON may both be escaped with
     * the same rules, even though there are additional escaping measures available
     * to JavaScript source code which aren’t applicable to serialized JSON data.
     *
     * A simple method safely escapes all content except for a few extremely rare and
     * unlikely exceptions: prevent the appearance of `<script` and `</script` within
     * the contents by replacing the first letter of the tag name with a Unicode escape.
     *
     * Example:
     *
     *     $plaintext = '<script>document.write( "A </script> closes a script." );</script>';
     *     $escaped   = '<script>document.write( "A </\u0073cript> closes a script." );</script>';
     *
     * This works because of how parsing changes after encountering an opening SCRIPT
     * tag. The actual parsing comprises a complicated state machine, the result of
     * legacy behaviors and diverse browser support. However, without these two strings
     * in the script contents, two key things are ensured: `</script>` cannot appear to
     * prematurely close the tag, and the problematic double-escaped state becomes
     * unreachable. A JavaScript engine or JSON decoder will then decode the Unicode
    ```

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

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

| Version | Description | 
| [6.2.0](https://developer.wordpress.org/reference/since/6.2.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_tag_processor%2Fparse_query%2F)
before being able to contribute a note or feedback.