Custom Post Type/taxonomy URL Structure

- 1 answer

I've had a quick scan through similar questions, but most don't seem to answer my question really.

I have a custom post type called, Products. Within there, I have taxonomies such as Room Type, Furniture Type, Material etc etc.

The site requires a really specific url structure to adhere to it's SEO strategy.

At the moment, i'm getting something like this:


I need to remove Room Type, essentially. I have tried setting "with_front" to false when registering the taxonomy, to no success.

Below is my current code, any help hugely appreciated.




        'label' => __( 'Room Type' ),
        'rewrite' => array( 

            'slug' => 'room-type',
            'with_front' => true,
            'hierarchical' => true,


        'hierarchical' => true,




So I did a little digging and found this page:

...and this is the code I have ended up with - which at the moment appears to be the closest thing I have come up with yet:

function sb_rewrites() {

    add_rewrite_rule( 'handles/([^/]+)/?', 'index.php?room-type=$matches[1]', 'top' );


add_action( 'init', 'sb_rewrites', 10, 0 );

function strip_room_type( $link, $term, $taxonomy ){

    if ( $taxonomy !== 'room-type' )

        return $link;

    return str_replace( 'room-type/', '', $link );


add_filter( 'term_link', 'strip_room_type', 10, 3 );




As I understand your question, I'm not sure there's a perfect way to remove that taxonomy slug. WordPress needs to know what sub taxonomy you're asking for in the URL, so it needs some sort of identifier. However, it appears there may be a work around in an answer to a similar question:

Essentially, defining verbose rewrite rules to 'force' the term out. But this can cause problems, which are better explained in the accepted answer here: