Below is how the URL layout is for my site using a Custom Post type called book and a custom tag taxonomy called book_tag

I am un-happy with the way Wordpress is writing the URL for my custom tag taxonomy. Below is an example of how my new post type and taxonomy are currently writing the URLs and how I would like it to do it.

Custom Post Type Name: book
Custom Taxonomy Name/Type: book_tag

Viewing the Index for my custom post type...


Viewing a custom post type single page...


Viewing a Custom Tag Taxonomy that is Linked for use on my Custom Post Type


I would like for the custom taxonomy to look more like it is under the custom post type like this...


or even better...


So currently a tag with the slug "css" is being wrote like this...


I would like it to be more like this...

http://website.com/book/book-tag/css/ or http://website.com/book/tag/css/ 

So my question, is this possible? To make the URL structure show a custom taxonomy to be UNDER a custom post type?

  • We have tons of posts about this URL pattern. Please add your research efforts to your question.
    – fuxia
    Sep 11, 2012 at 4:47
  • @toscho I have added an answer below, I am not sure how to call this for best performance though
    – JasonDavis
    Sep 11, 2012 at 4:59

1 Answer 1


After reading through about 20+ post on here, this is what I have come up with...

In this example http://test.com/{custom-post-type}/tag/{custom_taxonomy_name}/

Would do the trick I am after.

function custom_taxonomies_rewrite(){

I am not sure on the best way to call this though, right now it is called with init action. This seems like something that should only be called once and then the re-writes file rebuilt.

If this looks like the right way to do this, please tell me where I should be calling this code from, with init or another action/hook?

Your Answer

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

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