WP_Rewrite::add_rewrite_tag

Advertisement

Summery Summery

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

Syntax Syntax

WP_Rewrite::add_rewrite_tag( string $tag, string $regex, string $query )

Description Description

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

Parameters Parameters

$tag

(Required) Name of the rewrite tag to add or update.

$regex

(Required) Regular expression to substitute the tag for in rewrite rules.

$query

(Required) String to append to the rewritten query. Must end in '='.

Source Source

File: wp-includes/class-wp-rewrite.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;
		}
	}

Advertisement

Changelog Changelog

Changelog
Version Description
1.5.0 Introduced.

See also See also

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

Advertisement

Leave a Reply