WP_Rewrite::add_rewrite_tag()publicWP 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.

Метод класса: WP_Rewrite{}

Хуков нет.


null. Ничего (null).


global $wp_rewrite;
$wp_rewrite->add_rewrite_tag( $tag, $regex, $query );
$tag(строка) (обязательный)
Name of the rewrite tag to add or update.
$regex(строка) (обязательный)
Regular expression to substitute the tag for in rewrite rules.
$query(строка) (обязательный)
String to append to the rewritten query. Must end in '='.


  • Смотрите: WP_Rewrite::$rewritecode
  • Смотрите: WP_Rewrite::$rewritereplace
  • Смотрите: WP_Rewrite::$queryreplace

Список изменений

С версии 1.5.0 Введена.

Код WP_Rewrite::add_rewrite_tag() WP 6.5.3

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;