add_rewrite_rule

The timeline below displays how wordpress function add_rewrite_rule has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.3

/**
 * 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.
 *
 * @since 2.1.0
 * @since 4.4.0 Array support was added to the `$query` parameter.
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @param string       $regex Regular expression to match request against.
 * @param string|array $query The corresponding query vars for this rewrite rule.
 * @param string       $after Optional. Priority of the new rule. Accepts 'top'
 *                            or 'bottom'. Default 'bottom'.
 */
function add_rewrite_rule($regex, $query, $after = 'bottom')
{
    global $wp_rewrite;
    $wp_rewrite->add_rule($regex, $query, $after);
}

WordPress Version: 4.4

/**
 * 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.
 *
 * @since 2.1.0
 * @since 4.4.0 Array support was added to the `$query` parameter.
 *
 * @global WP_Rewrite $wp_rewrite WordPress Rewrite Component.
 *
 * @param string       $regex Regular expression to match request against.
 * @param string|array $query The corresponding query vars for this rewrite rule.
 * @param string       $after Optional. Priority of the new rule. Accepts 'top'
 *                            or 'bottom'. Default 'bottom'.
 */
function add_rewrite_rule($regex, $query, $after = 'bottom')
{
    global $wp_rewrite;
    $wp_rewrite->add_rule($regex, $query, $after);
}

WordPress Version: 4.3

/**
 * WordPress Rewrite API
 *
 * @package WordPress
 * @subpackage Rewrite
 */
/**
 * Add a straight rewrite rule.
 *
 * @since 2.1.0
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @param string $regex    Regular Expression to match request against.
 * @param string $redirect Page to redirect to.
 * @param string $after    Optional, default is 'bottom'. Where to add rule, can also be 'top'.
 */
function add_rewrite_rule($regex, $redirect, $after = 'bottom')
{
    global $wp_rewrite;
    $wp_rewrite->add_rule($regex, $redirect, $after);
}

WordPress Version: 3.7

/**
 * WordPress Rewrite API
 *
 * @package WordPress
 * @subpackage Rewrite
 */
/**
 * Add a straight rewrite rule.
 *
 * @see WP_Rewrite::add_rule() for long description.
 * @since 2.1.0
 *
 * @param string $regex Regular Expression to match request against.
 * @param string $redirect Page to redirect to.
 * @param string $after Optional, default is 'bottom'. Where to add rule, can also be 'top'.
 */
function add_rewrite_rule($regex, $redirect, $after = 'bottom')
{
    global $wp_rewrite;
    $wp_rewrite->add_rule($regex, $redirect, $after);
}