Is it possible to match site root with a WP rewrite rule?

I need to add a custom query var to the site root.

For example say I have a query var, lets say ‘colour’. I have a CPT called banana and I use the filter ‘banana_rewrite_rules’ to add ‘?colour=yellow’.

Read More

That works fine. If I visit www.example.com/bananas/ or www.example.com/banana/cavindish/ or /banana/wild/ I get the colour=yellow as a query var.

Now, I also have vars being returned for posts and pages. That works fine as well.

Thing is, I need to return a colour on the site root as well. If someone visits www.example.com I need, for example, ?colour=white returned and accessible as a query var.

So going on what I’ve done before, if I could match the site root itself to add the query var my filter remains unchanged. (root_rewrite_rules filter doesn’t work as it matches things like robots.txt, not the actual root).

Something like ‘^$’ which works in Django? Or ‘/?$’

Related posts

1 comment

Comments are closed.