1. Home
  2. Docs
  3. Features
  4. How to use the same permalink (rewrite) base for multiple post types & taxonomies?

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

Due to technical limitations WordPress users are not able to use the same permalink base for more than one content type. Permalink Manager allows to overcome this problem and define the same permalink format for multiple post types and taxonomies.

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

Why native WordPress permalinks use unique permalink rewrite base?

To begin with, the permalink (rewrite) base/slug in WordPress must be unique for each post type and taxonomy. Without that, WordPress will not be able to recognize what content element should be loaded. It happens because WordPress uses rewrite rules to detect the content types and reduce the number of database queries.

A proverb says that “the devil is in the details”. Each content type should have its own unique rewrite rule (permalink structure) for one simple reason. When a visitor tries to access any page, WordPress tries to compare the requested URL with an array of rewrite rules, that are actually regular expressions (or simply a set of permalink patterns). If requested permalink matches any of them, WP will translate the URI into a database query, load the correct template file and serve up the page or output “not found” error.

The problem here is that some rewrite rules (permalink formats) have higher priority than others and WordPress does not care if the post, page or term exists when it processes the URL. If you decide to use the same rewrite slug for eg. both products and product categories permalink, WordPress will recognize all the URLs with “shop” prefix as product category permalinks. Unfortunately, if a visitor access any product page, WordPress tries to load a non-existing product-category page.

# "Product category" permalink (working - WordPress detects them correctly)
http://example.com/shop/clothing
http://example.com/shop/clothing/men
http://example.com/shop/clothing/women

# "Product" permalinks (not working - WordPress treats them as product categories and returns 404 error)
http://example.com/shop/amazing-plain-t-shirt
http://example.com/shop/beautiful-white-cotton-dress 

How to force the same permalink rewrite base in WordPress with Permalink Manager?

It is not possible in a plain/vanilla version of WordPress, but you can easily overcome this issue with Permalink Manager. Below you can find a simple case study, but you can use it as an example and mirror in any more complex permalink structure.

Let’s say that we have one custom content type and two taxonomies (one hierarchical and one non-hierarchical) registered. As you can see, the rewrite slug (“car”) parameter is completely different for each content type.

Consequently, their native/original permalinks would look as follows:

# "Car" post type
http://example.com/car/fiesta-2015
http://example.com/car/s40-2017
http://example.com/car/m5-2016

# "Manufacturer" taxonomy
http://example.com/manufacturer/ford
http://example.com/manufacturer/volvo
http://example.com/manufacturer/bmw

# "Transmission" taxonomy
http://example.com/transmission/manual
http://example.com/transmission/automatic

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

# "Car" post type
http://example.com/car/ford/fiesta-2015
http://example.com/car/volvo/s40-2017
http://example.com/car/bmw/m5-2016

# "Manufacturer" taxonomy
http://example.com/car/ford
http://example.com/car/volvo
http://example.com/car/bmw

# "Transmisson" taxonomy
http://example.com/car/manual
http://example.com/car/automatic

Why Permalink Manager allows to duplicate the rewrite base in WordPress permalinks?

To make a long story short, Permalink Manager lets to define the same rewrite base/slug for multiple content types because it dose not use rewrite rules (regular expressions) to recognize the content. To be precies, it detects the posts and terms not by their slugs but their full custom permalinks altogether.

As long as you keep the permalinks unique (as a whole) Permalink Manager will detect them without any hassle. If you would like to get know how the custom permalinks are stored by the plugin here you can find a more detailed description.

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
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 you adjust the settings, please do not forget to save them using “Save permastructures” button in the very bottom.

Regenerate the custom permalinks for old posts & terms

After you set the permalink formats with new bases, Permalink Manager will correspondingly use them in all new posts and terms permalinks. If you would like to change them also in old elements, you will need to regenerate their permalinks. You can do so using “Regenerate/reset” tool available in “Tools -> Permalink Manger -> Tools” section. A more detailed instructions on how to reset them is available here.

Was this article helpful to you? Yes No