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 have a WordPress page which is accessible via /accommodation/.

What I want to be able to do is pass in a parameter using the URL - ie going to /accommodation/value1/ would load the same page as /accommodation/ - but still show the /accommodation/value1/ in the browser address bar.

I guess another way of putting it would be to say I need to be able to access /accommodation/ by adding anything I like to the end of the URL, whilst retaining the URL I entered in the browser window.

I've then got some code in the page template which does different things based on the values passed into the page.

Whilst I could use a query string, I want to avoid doing that so I can keep the "pretty URLs".

Many thanks for any help / suggestions.

share|improve this question
This is a good question, and particularly difficult. – WraithKenny Feb 16 '12 at 18:18
I've found a solution, but can't post it as an answer yet because it's a new-ish and question and I'm a new member. Will post it up when I'm able to! – gbuckingham89 Feb 16 '12 at 20:01

Solved it!

// Register the variables that will be used as parameters on the url
function add_my_var($public_query_vars) {
    $public_query_vars[] = 'extra_slug';
    return $public_query_vars;
add_filter('query_vars', 'add_my_var');

// Build the rewrite rules, for the extra parameter
function do_rewrite() {
    add_rewrite_rule('(accommodation)/[/]?([^/]*)$', 'index.php?pagename=accommodation&extra_slug=$matches[2]','top');
add_action('init', 'do_rewrite');

// The parameter is now accessible
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.