Outil de recherche WordPress pour les développeurs et auteurs de thèmes



add_rewrite_tag ›

Depuis2.1.0
Dépréciéen/a
add_rewrite_tag ( $tag, $regex, $query = '' )
Paramètres: (3)
  • (string) $tag Name of the new rewrite tag.
    Requis: Oui
  • (string) $regex Regular expression to substitute the tag for in rewrite rules.
    Requis: Oui
  • (string) $query Optional. String to append to the rewritten query. Must end in '='. Default empty.
    Requis: Non
    Défaut: (vide)
Défini(e) dans:
Codex:

Add a new rewrite tag (like %postname%).

The $query parameter is optional. If it is omitted you must ensure that you call this on, or before, the {@see 'init'} hook. This is because $query defaults to "$tag=", and for this to work a new query var has to be added.



Source

function add_rewrite_tag( $tag, $regex, $query = '' ) {
	// validate the tag's name
	if ( strlen( $tag ) < 3 || $tag[0] != '%' || $tag[ strlen( $tag ) - 1 ] != '%' ) {
		return;
	}

	global $wp_rewrite, $wp;

	if ( empty( $query ) ) {
		$qv = trim( $tag, '%' );
		$wp->add_query_var( $qv );
		$query = $qv . '=';
	}

	$wp_rewrite->add_rewrite_tag( $tag, $regex, $query );
}