On this page
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.
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
$regexstring Required-
Regular expression to match request against.
$querystring|array Required-
The corresponding query vars for this rewrite rule.
$afterstring Optional-
Priority of the new rule. Accepts
'top'or'bottom'. Default'bottom'.Default:
'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).
Source
File: wp-includes/rewrite.php. View all references
function add_rewrite_rule( $regex, $query, $after = 'bottom' ) {
global $wp_rewrite;
$wp_rewrite->add_rule( $regex, $query, $after );
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Rewrite::add_rule() wp-includes/class-wp-rewrite.php | Adds a rewrite rule that transforms a URL structure to a set of query vars. |
Used By
| Used By | Description |
|---|---|
| WP_Sitemaps::register_rewrites() wp-includes/sitemaps/class-wp-sitemaps.php | Registers sitemap rewrite tags and routing rules. |
| WP_Post_Type::add_rewrite_rules() wp-includes/class-wp-post-type.php | Adds the necessary rewrite rules for the post type. |
| rest_api_register_rewrites() wp-includes/rest-api.php | Adds REST rewrite rules. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/add_rewrite_rule