WordPress at a glance
function is not described

WP_Rewrite::add_rewrite_tag() public WP 1.5.0

Adds or updates existing rewrite tags (e.g. %postname%).

If the tag already exists, replace the existing pattern and query for that tag, otherwise add the new tag.

{} It's a method of the class: WP_Rewrite{}

No Hooks.

Return

Null. Nothing.

Usage

global $wp_rewrite;
$wp_rewrite->add_rewrite_tag( $tag, $regex, $query );
$tag(string) (required)
Name of the rewrite tag to add or update.
$regex(string) (required)
Regular expression to substitute the tag for in rewrite rules.
$query(string) (required)
String to append to the rewritten query. Must end in '='.

Notes

  • See: WP_Rewrite::$rewritecode
  • See: WP_Rewrite::$rewritereplace
  • See: WP_Rewrite::$queryreplace

Changelog

Since 1.5.0 Introduced.

Code of WP_Rewrite::add_rewrite_tag() WP 5.5.1

<?php
public function add_rewrite_tag( $tag, $regex, $query ) {
	$position = array_search( $tag, $this->rewritecode, true );
	if ( false !== $position && null !== $position ) {
		$this->rewritereplace[ $position ] = $regex;
		$this->queryreplace[ $position ]   = $query;
	} else {
		$this->rewritecode[]    = $tag;
		$this->rewritereplace[] = $regex;
		$this->queryreplace[]   = $query;
	}
}