We have a custom type music.


Also, we have a tag-like taxonomy genres. Its urls are:


I'm trying to make urls like:


/music-genres/ should be replaced by /music/genres/.

Finally we should get url structure like:


How do I do this?


3 Answers 3


Yes, this is possible, because your genres structure is /music/genres/[genre-name]. If it was /music/[genre-name] it would be complicated because it would conflict with /music/[post-name].

You just have to keep the order in mind. The rewrite rules should be ordered from most specific to least specific. If you first register the post type and then the taxonomy, the post type rules will come first. The problem is that the post type rules contain a very generic rule to match attachments, and this would mess with our taxonomy terms. But it will work if you first register the taxonomy and then the post type.

The confusing thing is that you normally pass the post types that will use the taxonomy you are registering, but you can just pass the empty array and make the connection later.

add_action( 'init', 'wpse13608_init' );
function wpse13608_init()
            'rewrite' => array(
                'slug' => 'music/genre'
    register_post_type( 'music' );
    register_taxonomy_for_object_type( 'music-genre', 'music' );

You can verify this and play with your rules with my Rewrite analyzer plugin.


Maybe you can find some information on this post: Custom post types, taxonomies, and permalinks

  • its not clear for me, can you please explain better? Commented Apr 2, 2011 at 15:51

WordPress does not support overloading permalink structures to the degree you want. You can write your own pre-rewrite filter to convert your desired URLs into URLs that WP_Rewrite can recognize, and then write filters to convert WordPress-generated links into your own style.

To understand this, study WP_Rewrite::generate_rewrite_rules and WP::parse_request, which are commonly regarded as "voodoo".

  • I'm a newbie in wordpress, please give a coded example. I've tryed something, had no luck. Commented Apr 6, 2011 at 23:28

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.