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 banging my head against a wall on this one for a while but I'm not quite sure from all the tutorials I read how to see why this isn't doing what I expect.

I have a page called shop-guide/shop-page?id=412 (for example)

and I want to change it so it it's shop-guide/shop-page/id/412/

As far as I can tell I have my code set up correctly, but when I try to navigate to the page I get a 404, and if I use the $_GET version it doesn't rewrite.

Here's my code: (in functions.php)

function wptuts_add_rewrite_rules() {  
add_action( 'init', 'wptuts_add_rewrite_rules' ); 
share|improve this question

Two issues -

your rewrite rule isn't formatted correctly, this:


should be:


and if shop-guide and shop-page are parent / child pages, this:


should be:

share|improve this answer
Thanks so much! That fixed it for me. – LetterAfterZ Jan 30 '13 at 0:40

I believe you first need to register your custom querystring variable. You could use add_rewrite_tag for this purpose: http://codex.wordpress.org/Rewrite_API/add_rewrite_rule

See the important note down at the bottom of the codex article


You could also use query_vars hook to add your own custom query variables.

share|improve this answer
Thanks, I've added the additional call (and in rewrite analyzer plugin it's working correctly), but the page is still returning a 404 instead of the actual page. function wptuts_add_rewrite_rules() { add_rewrite_tag('%id%','([^&]+)'); add_rewrite_rule( 'shop-guide/shop-page/id/([^/]*)/', 'index.php?p=143&id=$matches[1]', 'top' ); } add_action( 'init', 'wptuts_add_rewrite_rules' ); – LetterAfterZ Jan 30 '13 at 0:16

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.