Title: class@anonymous
Published: February 24, 2026
Last modified: August 20, 2026

---

# class class@anonymous {}

## In this article

 * [Methods](https://developer.wordpress.org/reference/classes/classanonymous/?output_format=md#methods)
 * [Source](https://developer.wordpress.org/reference/classes/classanonymous/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/classanonymous/?output_format=md#related)

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

## 󠀁[Methods](https://developer.wordpress.org/reference/classes/classanonymous/?output_format=md#methods)󠁿

| Name | Description | 
| [class@anonymous::get_span](https://developer.wordpress.org/reference/classes/classanonymous/get_span/) | Gets the span for the current token. | 
| [class@anonymous::insert_after](https://developer.wordpress.org/reference/classes/classanonymous/insert_after/) | Inserts text after the current token. | 
| [class@anonymous::insert_before](https://developer.wordpress.org/reference/classes/classanonymous/insert_before/) | Inserts text before the current token. | 
| [class@anonymous::remove](https://developer.wordpress.org/reference/classes/classanonymous/remove/) | Removes the current token. | 
| [class@anonymous::remove_token](https://developer.wordpress.org/reference/classes/classanonymous/remove_token/) | Removes the current token, keeping any text it wraps. | 
| [class@anonymous::replace](https://developer.wordpress.org/reference/classes/classanonymous/replace/) | Replaces the current token. | 
| [class@anonymous::replace_rich_text](https://developer.wordpress.org/reference/classes/classanonymous/replace_rich_text/) | Replace the rich text content between a tag opener and matching closer. |

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

    ```php
    $processor = new class( $buffer ) extends WP_HTML_Tag_Processor {
    	/**
    	 * Gets the span for the current token.
    	 *
    	 * @return WP_HTML_Span Current token span.
    	 */
    	private function get_span(): WP_HTML_Span {
    		// Note: This call will never fail according to the usage of this class, given it is always called after ::next_tag() is true.
    		$this->set_bookmark( 'here' );
    		return $this->bookmarks['here'];
    	}

    	/**
    	 * Inserts text before the current token.
    	 *
    	 * @param string $text Text to insert.
    	 */
    	public function insert_before( string $text ): void {
    		$this->lexical_updates[] = new WP_HTML_Text_Replacement( $this->get_span()->start, 0, $text );
    	}

    	/**
    	 * Inserts text after the current token.
    	 *
    	 * @param string $text Text to insert.
    	 */
    	public function insert_after( string $text ): void {
    		$span = $this->get_span();

    		$this->lexical_updates[] = new WP_HTML_Text_Replacement( $span->start + $span->length, 0, $text );
    	}

    	/**
    	 * Removes the current token.
    	 */
    	public function remove(): void {
    		$span = $this->get_span();

    		$this->lexical_updates[] = new WP_HTML_Text_Replacement( $span->start, $span->length, '' );
    	}

    	/**
    	 * Replaces the current token.
    	 *
    	 * @param string $text Text to replace with.
    	 */
    	public function replace( string $text ): void {
    		$span = $this->get_span();

    		$this->lexical_updates[] = new WP_HTML_Text_Replacement( $span->start, $span->length, $text );
    	}
    };
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/script-loader.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/script-loader.php#L3862)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/script-loader.php#L3862-L3913)

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

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

Core class used to modify attributes in an HTML document for tags matching a query.

  |

## User Contributed Notes

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