I’m game… have a beer… stay out of the htaccess file… keep your sanity… leave the wall alone…
First, you can go ahead and switch your permalinks to the pretty ones. Then you’ll get /PAGENAME/SUBPAGE/ and you’re half way there.
The key to the rest is the add_rewrite_endpoint function, it will do what you need (sort of… more like ?foo=bar… but you can take it from there). The code below is for PAGES, but you can change the second argument to turn it on for other items too.
Add something like this to your theme’s functions.php or your plugin:
// flush the rewrite rules
function foobar_flush_rewrite_rules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
add_action('init', 'foobar_flush_rewrite_rules');
// add foo as a possible "tail" item
add_rewrite_endpoint('foo',EP_PAGES);
// add foo as an allowed query var
function foobar_variables($public_query_vars) {
$public_query_vars[] = 'foo';
return $public_query_vars;
}
add_filter('query_vars', 'foobar_variables');
// OPTIONAL - sample filter action if the query var is seen -
// I'm using it to toss in an extra stylesheet that changes the page's
// appearance
function foobar_add_stylesheet() {
// check for variants in link structure
if (get_query_var('foo')) {
// add stylesheet to hide certain divs
echo "\n".
'<style type="text/css" media="screen">@import "' .
get_bloginfo('stylesheet_directory') .
'/foo.css";</style>'."\n";
}
}
add_action('wp_head', 'foobar_add_stylesheet', 1);
You can also use the get_query_var() function on template pages to deal with your parameters.
I have no idea if this will work with more than one endpoint.
Awesome, thank you! I will try this out tonight and report back on how it works out for me.
Thanks
Dave
Worked like a charm, thanks a ton Roger!