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
    # "Manufacturer" taxonomy
    # "Transmission" taxonomy

    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
    # "Manufacturer" taxonomy
    # "Transmisson" taxonomy


    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
    Replace car/%car% with car/%manufacturer%/car%
    # "Manufacturer" taxonomy
    Replace manufacturer/%manufacturer% with car/%manufacturer%
    # "Transmission" taxonomy
    Replace transmission/%transmisson% with car/%transmission%
    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 *