How to use the same permalink (rewrite) base for multiple post types & taxonomies?

Due to WordPress limitations (rewrite rules based on regular expressions) it is not possible to use the same permalink base for more than one content type: custom post type or taxonomy without a sophisticated solution.

Still, if you would like to make your permalinks more coherent to boost your SEO score and set-up the same permalink bases for different post types & taxonomies you can use Permalink Manager to bypass this technical barrier.

In this short tutorial you will learn how to use the identical permalinks base in three sample content types and bypass rewrite rules limitations. This example case study should help you achieve the same effect with specific custom post types & taxonomies structure on your website.

Some of the functionalities presented in this post are available only in Permalink Manager Pro.
Buy the plugin here.

Table of contents

    What is the problem in our case study?

    As already pointed out, the permalinks bases in WordPress must be unique for each post type and taxonomy. Let’s say that we have one custom content type and two taxonomies (one hierarchical and one non-hierarchical) registered.

    Sample PHP code snippet:

    The same effect can be achieved also with 3rd party plugins, eg. PODS or Toolset Types.

    function bis_register_cpt() {
    	register_post_type( 'car', array(
    		'label'                 => __( 'Cars', 'bis' ),
    		'supports'              => array( 'title', 'editor', 'custom-fields', 'thumbnail'),
    		'hierarchical'          => false,
    		'public'                => true,
    		'has_archive'           => true,
    		'capability_type'       => 'page',
    		'rewrite'               => array( 'slug' => 'car' ),
    	));
    
    	register_taxonomy( 'car-brand', array( 'car' ), array(
    		'label'                 => __( 'Brand', 'bis' ),
    		'hierarchical'          => true,
    		'public'                => true,
    		'rewrite'               => array( 'slug' => 'car-brand' ),
    	) );
    
    	register_taxonomy( 'car-color', array( 'car' ), array(
    		'label'                 => __( 'Color', 'bis' ),
    		'hierarchical'          => false,
    		'public'                => true,
    		'rewrite'               => array( 'slug' => 'car-color' ),
    	) );
    }
    add_action( 'init', 'bis_register_cpt', 0 );
    

    As you can see, the “rewrite slug” parameter is completely different for each content type. If it is not unique, the rewrite rules will overwrite themselves and the posts or terms will not be detected correctly by WordPress (more info here).

    The native permalinks would look like this:

    # "Car" post type
    http://example.com/cars/ford-fiesta-2015
    http://example.com/cars/volvo-s40-2017
    http://example.com/cars/bmw-m5-2016
    
    # "Car brand" taxonomy
    http://example.com/car-brand/ford
    http://example.com/car-brand/ford/fiesta
    http://example.com/car-brand/volvo
    http://example.com/car-brand/volvo/s40
    http://example.com/car-brand/bmw
    http://example.com/car-brand/bmw/m5
    
    # "Car color" taxonomy
    http://example.com/car-color/red
    http://example.com/car-color/green
    http://example.com/car-color/blue
    

    Desired result and why it works?

    With Permalink Manager it is possible to set-up the same permalink base for multiple content types because the plugin detects the terms or posts not by their slugs but their full custom permalinks altogether.

    As long as you keep the permalinks unique (as a whole) it will not be a problem to detect them with Permalink Manager. You can find more information about how the custom permalinks are stored by the plugin here.

    Our goal is to share the same base (“cars”) in all three content types’ permalinks:

    # "Car" post type
    http://example.com/cars/ford-fiesta-2015
    http://example.com/cars/volvo-s40-2017
    http://example.com/cars/bmw-m5-2016
    
    # "Car brand" taxonomy
    http://example.com/cars/ford
    http://example.com/cars/ford/fiesta
    http://example.com/cars/volvo
    http://example.com/cars/volvo/s40
    http://example.com/cars/bmw
    http://example.com/cars/bmw/m5
    
    # "Car color" taxonomy
    http://example.com/cars/red
    http://example.com/cars/green
    http://example.com/cars/blue
    

    Instructions

    Step 1. Change the native permastrucutres

    To adjust the permalinks, you should start with custom permastructures settings that can be edited in “Tools -> Permalink Manager” section (“Permastructures” tab).

    Original settings

    Permastructure settings:

    # "Car" post type
    The permastructure settings should not be changed: cars/%car%
    
    # "Car brand" taxonomy
    Replace car-brand/%car-brand% with cars/%car-brand%
    
    # "Car color" taxonomy
    Replace car-color/%car-color% with cars/%car-color%
    
    New settings

    After the new settings are applied, please do not forget to save them using “Save permastructures” button in the very bottom.

    Regenerate the custom permalinks for old posts & terms

    The saved configuration will be immediately used for default permalinks of new posts and terms. If you would like to use it also for old permalinks as well, please follow the instructions available here.

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    *

    *

    *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Wait!!! Before you go...

    Still not convinced? Use following discount code during Gumroad checkout and get 10% off!

    BLOG

    If you have any questions or need further information, please feel free to contact me via email: