Using WordPress ‘remove_rewrite_tag()’ PHP function

The remove_rewrite_tag() WordPress PHP function removes an existing rewrite tag, like %postname%.

Usage

To remove a rewrite tag, call the function and pass the rewrite tag as a parameter:

remove_rewrite_tag('%example_tag%');

Parameters

  • $tag (string) – The name of the rewrite tag you want to remove.

More information

See WordPress Developer Resources: remove_rewrite_tag()

Examples

Remove a custom rewrite tag

Remove a custom rewrite tag named %custom_tag%:

add_action('init', 'remove_custom_rewrite_tag');
function remove_custom_rewrite_tag() {
    remove_rewrite_tag('%custom_tag%');
}

Remove %category% rewrite tag

Remove the %category% rewrite tag:

add_action('init', 'remove_category_rewrite_tag');
function remove_category_rewrite_tag() {
    remove_rewrite_tag('%category%');
}

Remove %author% rewrite tag

Remove the %author% rewrite tag:

add_action('init', 'remove_author_rewrite_tag');
function remove_author_rewrite_tag() {
    remove_rewrite_tag('%author%');
}

Remove %year% rewrite tag

Remove the %year% rewrite tag:

add_action('init', 'remove_year_rewrite_tag');
function remove_year_rewrite_tag() {
    remove_rewrite_tag('%year%');
}

Remove %monthnum% rewrite tag

Remove the %monthnum% rewrite tag:

add_action('init', 'remove_monthnum_rewrite_tag');
function remove_monthnum_rewrite_tag() {
    remove_rewrite_tag('%monthnum%');
}