add_rewrite_rule( string $regex, string|array $query, string $after = 'bottom' )

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.



(string) (Required) Regular expression to match request against.


(string|array) (Required) The corresponding query vars for this rewrite rule.


(string) (Optional) Priority of the new rule. Accepts 'top' or 'bottom'.

Default value: 'bottom'

More Information

add_rewrite_rule() allows you to specify additional rewrite rules for WordPress. It is most commonly used in conjunction with add_rewrite_tag() (which allows WordPress to recognize custom post/get variables).


File: wp-includes/rewrite.php

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

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


Version Description
4.4.0 Array support was added to the $query parameter.
2.1.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.