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.

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.


Null. Nothing.


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'


  • Global. WP_Rewrite. $wp_rewrite WordPress rewrite component.


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

Code of add_rewrite_rule() WP 5.6

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

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

From tag: Rewrite (clean friendly URL)

No comments
    Log In