Since you want to add something to the end of every post/page rewrite rule, you probably can just add a rewrite endpoint . These are regexes of the form /[endpoint_name](/[optional_extra_stuff])? that are appended to the already generated rules for pages, posts, archives, ...

You define on which structures you want to add them by setting the endpoint mask . This is a bitmask, so you can combine different groups using the | operator, like this: EP_PERMALINK | EP_PAGES will match for every page and every permalink (full post and date-based archives). The default list of endpoints can be found at the top of wp-includes/rewrite.php .

The following code will add /remove(/(.*))? to the existing rewrite rules for pages, posts and date-based archives (for some reason they are generated twice, once in EP_PERMALINK and once in EP_DATE ). remove will also be available as a public query var, so you can do $wp_query-> get( 'remove' ) to get the value (if set) of the [optional_extra_stuff] in the URL.



add_filter( 'init', 'wpse2614_init' );
function wpse2614_init()
{ add_rewrite_endpoint( 'remove', EP_PERMALINK | EP_PAGES );
}


More Solution