WordPress at a glance

add_rewrite_rule() WP 1.0

Adds a rewrite rule that transforms a URL structure to a set of query vars.

Any value in the $after parameter that isn't 'bottom' will result in the rule being placed at the top of the rewrite rules.

  • Global. WP_Rewrite. $wp_rewrite WordPress Rewrite Component.
  • Since 4.4.0 Array support was added to the $query parameter.
Works based on: WP_Rewrite::add_rule()
✈ 1 time = 0.000001s = speed of light | 50000 times = 0.03s = speed of light PHP 7.1.11, WP 4.9.8

No Hooks.


Nothing (null).


add_rewrite_rule( $regex, $query, $after );
$regex(string) (required)
Regular expression to match request against.
$query(string/array) (required)
The corresponding query vars for this rewrite rule.
Priority of the new rule. Accepts 'top' or 'bottom'.
Default: 'bottom'

Code of add_rewrite_rule: wp-includes/rewrite.php VER 5.0.1

function add_rewrite_rule( $regex, $query, $after = 'bottom' ) {
	global $wp_rewrite;

	$wp_rewrite->add_rule( $regex, $query, $after );

Related Functions

From tag: Rewrite (clean friendly URL)

No comments
    Hello, !     Log In . Register