add_rewrite_rule
Adds a rewrite rule that transforms a URL structure to a set of query vars.
Description
Any value in the $after
parameter that isn't bottom will result in the rule being placed at the top of the rewrite rules.
Parameters (3)
- 0. $regex (string)
- Regular expression to match request against.
- 1. $query (string|array)
- The corresponding query vars for this rewrite rule.
- 2. $after — Optional. (string) =>
'bottom'
- Priority of the new rule. Accepts top or bottom.. Default bottom..
Usage
if ( !function_exists( 'add_rewrite_rule' ) ) { require_once ABSPATH . WPINC . '/rewrite.php'; } // Regular expression to match request against. $regex = ''; // The corresponding query vars for this rewrite rule. $query = null; // Optional. Priority of the new rule. Accepts 'top' // or 'bottom'. Default 'bottom'. $after = 'bottom'; // NOTICE! Understand what this does before running. $result = add_rewrite_rule($regex, $query, $after);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/rewrite.php
- function add_rewrite_rule( $regex, $query, $after = 'bottom' ) {
- global $wp_rewrite;
- $wp_rewrite->add_rule( $regex, $query, $after );
- }