WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Is the -with-* neccessary? Wouldn't it be simpler to add a querystring. – Shane Jan 24 '12 at 16:25
@Shane yes unfortunately so. – Mig Jan 24 '12 at 16:27
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. – chrisguitarguy Sep 8 '12 at 5:16

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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