0

I have a taxonomy location. All terms except one are to be treated differently. That's why I have two php files

  1. taxonomy-location.php
  2. taxonomy-location-national.php

Now, I want to make the URLs SEO friendly.

If URL = example.com/localdeals/national, I want to redirect it to taxonomy-location-national.php

If URL = example.com/localdeals/%any-other-term%, I want to redirect it to taxonomy-location.php

Basically I do not want to write the name of above files in .htaccess. I want to, somehow, reuse the default WordPress rules.

i.e. WordPress already directs example.com/?location=national and example.com/?location=boston correctly. I want to add new rules on top of these and want to reuse them.

Is it possible?

1 Answer 1

0

Note that the url-rewriting doesn't directly determine the template used. A pretty url is interpreted as a query and then that query determines what template is used based on the template hierarchy.

So only need one rule:

example.com/localdeals/myterm => example.com/?location=myterm

WordPress will look for the template taxonomy-location-myterm.php and use that (if it exists) or otherwise fallback to taxonomy-location.php

To add the above rule, when you register your taxonomy:

  register_taxonomy('location','post',array(
    'hierarchical' => false,
     ...
    'query_var' => true,
    'rewrite' => array( 'slug' => 'localdeals' ),
     ...
  ));

(you will need to flush these rules once after changing these - if this is for a plug-in/theme, only flush on activation/de-activation). Otherwise, just visit Settings > Permlinks page, and they'll be flushed :).

0

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.