wordpress url resolution of subpages from within plugin

Say I have a Page “foo” in wordpress such that http:/www.blah.com/foo brings it up.

Say this page has a trigger within its content such as <!– foo –!> which is being tracked by my plugin through the add_filter(‘the_content’, ..) filter. So, all calls to http:www.blah.com/foo and http://www.blah.com/foo?var=bar are picked up by the plugin and dealt with.

Read More

Now is there a way by which the plugin could let wordpress know that it wants to handle all urls of the type http://www.blah.com/foo/bar http://www.blah.com/foo/bar/morefoo etc..
“without” having to create pages/subpages for each of these as these urls would be created dynamically?

Also, is there anyway besides using the add_content filter on the_content within a page that one can grab control from within a plugin ideally keyed of the url so all calls to http://www.blah.com/foo are handled by the plugin.

Related posts

Leave a Reply

3 comments

  1. I do something very similar to what you describe using a custom mod_rewrite rule. Following your example, I have a page Foo that uses the template foo.php. The foo.php template accepts a query variable, say “path”, that defines the remainder of the URL. In my .htaccess file, I have the following rule (be careful to put it outside WordPress’ automatically-generated rules!):

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^foo/(.+) /foo/?path=$1 [L] 
    </IfModule>
    

    Your plugin may also need to disable the “redirect_canonical” plugin, which can poach your URLs unexpectedly.

    remove_action('template_redirect', 'redirect_canonical');
    

    I think it may also be possible to do something similar using the template_redirect hook and WP_Rewrite class, but I have not tried it myself.