I've been scratching my head about this one for a while. I have tried to add a hook within WP_Rewrite to ensure that we can pick up pages with a similar structure:


The actual page, would be /products/product1. The end result would be that the * would be used in the page (once processed) to transform it or change the theme etc.

It seems that the following is available in WordPress:

  • add_rewrite_endpoint: This seems to do what I want, but without the URL format I am after. This would yield something like /with/* which is not what I want ideally.
  • adding a new route: This seems overkill for what I need, ideally I don't want to modify/create multiple routes just to tranform the existing ones.

I have also tried a few of the normal filters such as parse_query and pre_get_posts but it seems most of the work of deciding what page to display has been decided at these points.

Is there a relatively simple way to parse the URL when requested and strip out the with-* part until needed within the page?

If not, how would it be accomplished with the new route method?

  • 2
    Is the -with-* neccessary? Wouldn't it be simpler to add a querystring.
    – Shane
    Commented Jan 24, 2012 at 16:25
  • @Shane yes unfortunately so.
    – Hux
    Commented Jan 24, 2012 at 16:27
  • 1
    I would recommend sucking it up and going with the end point. You can certainly do the other way with rewrite rules, but it's going to be more complex. Slash delimiters for things in URLs just work -- for obvious reasons. Commented Sep 8, 2012 at 5:16

1 Answer 1


Yes, you sure can manipulate the URL. From what you are describing it seems rather pointless, though.

The simplest approach to do what you are asking, or seemingly getting at, is to use a switch case in the header.php

If you really need control of the switch case you can feed it theme option data or post/page metadata.

PHP Simplified version

switch (n)
case label1:
  code to be executed if n=label1;
case label2:
  code to be executed if n=label2;
  code to be executed if n is different from both label1 and label2;

Or you can see a more advanced version I wrote a tutorial on using sample wordpress functions at


Which should tell you how you can integrate queries into your switch statement easily.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.