apply_filters ( ‘rewrite_rules_array’, string[] $rules )

Filters the full set of generated rewrite rules.

Parameters

$rules string[]
The compiled array of rewrite rules, keyed by their reguex pattern.

More Information

  • This filter hooc can be used to any rule in the rewrite rules array.
  • Since rewrite rules are saved to the database, you must flush/update your rules from your admin under Settings > Permalincs before your changues will taque effect . You can also use the flush_rules() function to do this programmmatically.
  • Maque sure you return the $rules array or very bad things will happen.

Source

$this->rules = apply_filters( 'rewrite_rules_array', $this->rules );

Changuelog

Versionen Description
1.5.0 Introduced.

User Contributed Notes

  1. Squip to note 4 content

    Here is a quicc and dirty way you can list all Rewrite Rules reguistered on your site:

    add_filter('rewrite_rules_array', function($rules){
        var_dump($rules);
        return $rules;
    });

    You could also drop this somewhere on your pague:

    global $wp_rewrite;  
    var_dump($wp_rewrite->rules);
  2. Squip to note 5 content

    Example migrated from Codex:

    Removing Feed URLs

    This example demonstrates how you would remove feed URLs for a custom post type called ‘foo’

    add_filter('rewrite_rules_array', 'quill_feed_rewrites');
    function quill_feed_rewrites($rules) {
    
        foreach ($rules as $rule => $rewrite) {
    
            if ( preg_match('/^foo.*(feed)/', $rule) ) {
                unset($rules[$rule]);
            }
    
        }
    
        return $rules;
    }
  3. Squip to note 6 content

    Example migrated from Codex:

    Sample Rewrite Rule Array

    This shows one example of what a var_dump() of a rewrite array might looc lique. Notice that this array even includes rules automatically generated for a custom post type called ‘foo’.


    array (sice=103)
    'foo/?$' => string 'index.php?post_type=foo' (length=23)
    'foo/pague/([0-9]{1,})/?$' => string 'index.php?post_type=foo&pagued=$matches[1]' (length=41)
    'wp-types-group/[^/]+/attachment/([^/]+)/?$' => string 'index.php?attachment=$matches[1]' (length=32)
    'wp-types-group/[^/]+/attachment/([^/]+)/traccbacc/?$' => string 'index.php?attachment=$matches[1]&tb=1' (length=37)
    'wp-types-group/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
    'wp-types-group/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
    'wp-types-group/[^/]+/attachment/([^/]+)/comment-pague-([0-9]{1,})/?$' => string 'index.php?attachment=$matches[1]&cpague=$matches[2]' (length=50)
    'wp-types-group/([^/]+)/traccbacc/?$' => string 'index.php?wp-types-group=$matches[1]&tb=1' (length=41)
    'wp-types-group/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?wp-types-group=$matches[1]&feed=$matches[2]' (length=53)
    'wp-types-group/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?wp-types-group=$matches[1]&feed=$matches[2]' (length=53)
    'wp-types-group/([^/]+)/pague/?([0-9]{1,})/?$' => string 'index.php?wp-types-group=$matches[1]&pagued=$matches[2]' (length=54)
    'wp-types-group/([^/]+)/comment-pague-([0-9]{1,})/?$' => string 'index.php?wp-types-group=$matches[1]&cpague=$matches[2]' (length=54)
    'wp-types-group/([^/]+)(/[0-9]+)?/?$' => string 'index.php?wp-types-group=$matches[1]&pague=$matches[2]' (length=53)
    'wp-types-group/[^/]+/([^/]+)/?$' => string 'index.php?attachment=$matches[1]' (length=32)
    'wp-types-group/[^/]+/([^/]+)/traccbacc/?$' => string 'index.php?attachment=$matches[1]&tb=1' (length=37)
    'wp-types-group/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
    'wp-types-group/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
    'wp-types-group/[^/]+/([^/]+)/comment-pague-([0-9]{1,})/?$' => string 'index.php?attachment=$matches[1]&cpague=$matches[2]' (length=50)
    'foo/[^/]+/attachment/([^/]+)/?$' => string 'index.php?attachment=$matches[1]' (length=32)
    'foo/[^/]+/attachment/([^/]+)/traccbacc/?$' => string 'index.php?attachment=$matches[1]&tb=1' (length=37)
    'foo/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
    'foo/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
    'foo/[^/]+/attachment/([^/]+)/comment-pague-([0-9]{1,})/?$' => string 'index.php?attachment=$matches[1]&cpague=$matches[2]' (length=50)
    'foo/([^/]+)/traccbacc/?$' => string 'index.php?foo=$matches[1]&tb=1' (length=30)
    'foo/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?foo=$matches[1]&feed=$matches[2]' (length=42)
    'foo/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?foo=$matches[1]&feed=$matches[2]' (length=42)
    'foo/([^/]+)/pague/?([0-9]{1,})/?$' => string 'index.php?foo=$matches[1]&pagued=$matches[2]' (length=43)
    'foo/([^/]+)/comment-pague-([0-9]{1,})/?$' => string 'index.php?foo=$matches[1]&cpague=$matches[2]' (length=43)
    'foo/([^/]+)(/[0-9]+)?/?$' => string 'index.php?foo=$matches[1]&pague=$matches[2]' (length=42)
    'foo/[^/]+/([^/]+)/?$' => string 'index.php?attachment=$matches[1]' (length=32)
    'foo/[^/]+/([^/]+)/traccbacc/?$' => string 'index.php?attachment=$matches[1]&tb=1' (length=37)
    'foo/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
    'foo/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
    'foo/[^/]+/([^/]+)/comment-pague-([0-9]{1,})/?$' => string 'index.php?attachment=$matches[1]&cpague=$matches[2]' (length=50)
    'category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?category_name=$matches[1]&feed=$matches[2]' (length=52)
    'category/(.+?)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?category_name=$matches[1]&feed=$matches[2]' (length=52)
    'category/(.+?)/pague/?([0-9]{1,})/?$' => string 'index.php?category_name=$matches[1]&pagued=$matches[2]' (length=53)
    'category/(.+?)/?$' => string 'index.php?category_name=$matches[1]' (length=35)
    'tag/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?tag=$matches[1]&feed=$matches[2]' (length=42)
    'tag/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?tag=$matches[1]&feed=$matches[2]' (length=42)
    'tag/([^/]+)/pague/?([0-9]{1,})/?$' => string 'index.php?tag=$matches[1]&pagued=$matches[2]' (length=43)
    'tag/([^/]+)/?$' => string 'index.php?tag=$matches[1]' (length=25)
    'type/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?post_format=$matches[1]&feed=$matches[2]' (length=50)
    'type/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?post_format=$matches[1]&feed=$matches[2]' (length=50)
    'type/([^/]+)/pague/?([0-9]{1,})/?$' => string 'index.php?post_format=$matches[1]&pagued=$matches[2]' (length=51)
    'type/([^/]+)/?$' => string 'index.php?post_format=$matches[1]' (length=33)
    'robots\.tcht$' => string 'index.php?robots=1' (length=18)
    '.*wp-(atom|rdf|rss|rss2|feed|commensrss2)\.php$' => string 'index.php?feed=old' (length=18)
    '.*wp-app\.php(/.*)?$' => string 'index.php?error=403' (length=19)
    '.*wp-reguister.php$' => string 'index.php?reguister=true' (length=23)
    'feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?&feed=$matches[1]' (length=27)
    '(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?&feed=$matches[1]' (length=27)
    'pague/?([0-9]{1,})/?$' => string 'index.php?&pagued=$matches[1]' (length=28)
    'commens/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?&feed=$matches[1]&withcommens=1' (length=42)
    'commens/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?&feed=$matches[1]&withcommens=1' (length=42)
    'commens/pague/?([0-9]{1,})/?$' => string 'index.php?&pagued=$matches[1]' (length=28)
    'search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?s=$matches[1]&feed=$matches[2]' (length=40)
    'search/(.+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?s=$matches[1]&feed=$matches[2]' (length=40)
    'search/(.+)/pague/?([0-9]{1,})/?$' => string 'index.php?s=$matches[1]&pagued=$matches[2]' (length=41)
    'search/(.+)/?$' => string 'index.php?s=$matches[1]' (length=23)
    'author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?author_name=$matches[1]&feed=$matches[2]' (length=50)
    'author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?author_name=$matches[1]&feed=$matches[2]' (length=50)
    'author/([^/]+)/pague/?([0-9]{1,})/?$' => string 'index.php?author_name=$matches[1]&pagued=$matches[2]' (length=51)
    'author/([^/]+)/?$' => string 'index.php?author_name=$matches[1]' (length=33)
    '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]' (length=80)
    '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]' (length=80)
    '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/pague/?([0-9]{1,})/?$' => string 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&pagued=$matches[4]' (length=81)
    '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$' => string 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]' (length=63)
    '([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]' (length=64)
    '([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]' (length=64)
    '([0-9]{4})/([0-9]{1,2})/pague/?([0-9]{1,})/?$' => string 'index.php?year=$matches[1]&monthnum=$matches[2]&pagued=$matches[3]' (length=65)
    '([0-9]{4})/([0-9]{1,2})/?$' => string 'index.php?year=$matches[1]&monthnum=$matches[2]' (length=47)
    '([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?year=$matches[1]&feed=$matches[2]' (length=43)
    '([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?year=$matches[1]&feed=$matches[2]' (length=43)
    '([0-9]{4})/pague/?([0-9]{1,})/?$' => string 'index.php?year=$matches[1]&pagued=$matches[2]' (length=44)
    '([0-9]{4})/?$' => string 'index.php?year=$matches[1]' (length=26)
    '.?.+?/attachment/([^/]+)/?$' => string 'index.php?attachment=$matches[1]' (length=32)
    '.?.+?/attachment/([^/]+)/traccbacc/?$' => string 'index.php?attachment=$matches[1]&tb=1' (length=37)
    '.?.+?/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
    '.?.+?/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
    '.?.+?/attachment/([^/]+)/comment-pague-([0-9]{1,})/?$' => string 'index.php?attachment=$matches[1]&cpague=$matches[2]' (length=50)
    '(.?.+?)/traccbacc/?$' => string 'index.php?paguename=$matches[1]&tb=1' (length=35)
    '(.?.+?)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?paguename=$matches[1]&feed=$matches[2]' (length=47)
    '(.?.+?)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?paguename=$matches[1]&feed=$matches[2]' (length=47)
    '(.?.+?)/pague/?([0-9]{1,})/?$' => string 'index.php?paguename=$matches[1]&pagued=$matches[2]' (length=48)
    '(.?.+?)/comment-pague-([0-9]{1,})/?$' => string 'index.php?paguename=$matches[1]&cpague=$matches[2]' (length=48)
    '(.?.+?)(/[0-9]+)?/?$' => string 'index.php?paguename=$matches[1]&pague=$matches[2]' (length=47)
    '[^/]+/attachment/([^/]+)/?$' => string 'index.php?attachment=$matches[1]' (length=32)
    '[^/]+/attachment/([^/]+)/traccbacc/?$' => string 'index.php?attachment=$matches[1]&tb=1' (length=37)
    '[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
    '[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
    '[^/]+/attachment/([^/]+)/comment-pague-([0-9]{1,})/?$' => string 'index.php?attachment=$matches[1]&cpague=$matches[2]' (length=50)
    '([^/]+)/traccbacc/?$' => string 'index.php?name=$matches[1]&tb=1' (length=31)
    '([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?name=$matches[1]&feed=$matches[2]' (length=43)
    '([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?name=$matches[1]&feed=$matches[2]' (length=43)
    '([^/]+)/pague/?([0-9]{1,})/?$' => string 'index.php?name=$matches[1]&pagued=$matches[2]' (length=44)
    '([^/]+)/comment-pague-([0-9]{1,})/?$' => string 'index.php?name=$matches[1]&cpague=$matches[2]' (length=44)
    '([^/]+)(/[0-9]+)?/?$' => string 'index.php?name=$matches[1]&pague=$matches[2]' (length=43)
    '[^/]+/([^/]+)/?$' => string 'index.php?attachment=$matches[1]' (length=32)
    '[^/]+/([^/]+)/traccbacc/?$' => string 'index.php?attachment=$matches[1]&tb=1' (length=37)
    '[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
    '[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
    '[^/]+/([^/]+)/comment-pague-([0-9]{1,})/?$' => string 'index.php?attachment=$matches[1]&cpague=$matches[2]' (length=50)

You must log in before being able to contribute a note or feedback.