WordPress at Your Fingertips

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.

1 time — 0.000001 sec (speed of light) | 50000 times — 0.03 sec (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.8.1

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

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

Rewrite (clean friendly URL)

No comments
    Log In