How to Add Taxonomy Slugs to Custom Post Type Permalinks

By default, custom post type URLs contain only the post type base and the post slug, for example, /sales/john-doe/.

Including a taxonomy term in the URL, as in /sales/europe/switzerland/john-doe/, usually requires additional rewrite rules, which can conflict with existing rules and cause 404 errors. If you are changing existing permalinks, you also need to set up redirects from the old URLs.

Permalink Manager supports this natively. You can include one or more taxonomy slugs in your permalink structure under Tools → Permalink Manager → Permastructures, without writing or implementing custom code.

Add category to custom permalinks

Adding Taxonomies to Custom Post Type Permalinks

Depending on your content structure, you can use a single custom taxonomy or combine several taxonomies to create hierarchical, more descriptive URLs. This works much like adding categories to the URLs of standard posts.

For example, to include both the Fuel and Manufacturer taxonomies in the URLs of the Cars post type, set its permalink structure to:

%fuel%/%manufacturer%/%car%

A car assigned to the Diesel and Ford terms will then have the following URL:

https://example.com/diesel/ford/ford-fiesta/

Step 1: Configure Permastructure Settings

To add taxonomy tags to a custom post type's permalink structure, open Tools → Permalink Manager → Permastructures.

Find the custom post type you want to modify, then enter the taxonomy tags directly into its input field. Wrap each taxonomy name in percent signs, for example, %fuel% or %manufacturer%.

Adding category to custom post type permalinks

New permastructure settings for custom post type

To view all available permastructure tags for your taxonomies, click the "Available tags" button below the input field.
List of available tags

Step 2: Applying Changes to Existing Permalinks

The new format applies only to newly published posts. Saving a new permastructure does not update existing URLs automatically

This is intentional. It helps prevent unexpected changes to URLs that search engines have already indexed or that other websites link to.

If you want to keep your existing URLs unchanged, you do not need to do anything else. To apply the new format to existing posts as well, use the Regenerate/reset tool.

What happens to the old URLs after you regenerate them?

  • If a post previously used the default WordPress permalink, the plugin automatically redirects it to the new URL. This also works in the free version of Permalink Manager.
  • If the old URL was a custom permalink, the redirect works only if you enable both Extra redirects (aliases) and Save old custom permalinks as extra redirects in the plugin settings. Both options require Permalink Manager Pro.
A sample post permalink with category slug included
Both Manufacturer & Fuel terms' slugs are now present in the custom permalink for new single Car post.

How Permalink Manager Chooses the Taxonomy Term?

The plugin supports both hierarchical and non-hierarchical taxonomies in custom post type permalink structures. By default, it adds taxonomy slugs to custom post type URLs, similar to how WordPress can include category slugs in post URLs.

Most ready code snippets skip parent slugs when a taxonomy has a parent-child structure. Permalink Manager plugin supports this out-of-box. For hierarchical taxonomies, it automatically uses the lowest-level term and adds all parent slugs to the URL.

For example, if a product belongs to "Clothing → T-Shirts → Cotton", the permalink will contain all category (taxonomy) slugs:

http://example.com/%product_cat%/%product%

http://example.com/clothing/t-shirts/cotton/happy-ninja
http://example.com/clothing/jackets/leather/biker-black

The plugin allows you to set a different term for the CPT permalink. If you select a primary category, its slug will be used in the URL instead.

If you want shorter URLs and do not want all parent slugs included, you can use alternative taxonomy tags. You can choose to include only the highest level term slug or only the deepest one in the custom post type permalink.

How to Use the Highest-Level Taxonomy (Category) Slug?

To display only the highest-level parent term, append "_top" to your taxonomy tag.
For example, replace %product_cat% with %product_cat_top%.

http://example.com/%product_cat_top%/%product%

http://example.com/clothing/happy-ninja
http://example.com/clothing/biker-black

How to Use the Lowest-Level Taxonomy (Category) Slug?

To display only the deepest child term, append "_flat" to your taxonomy tag.
For example, replace %product_cat% with %product_cat_flat%.

http://example.com/%product_cat_flat%/%product%

http://example.com/cotton/happy-ninja
http://example.com/leather/biker-black

Remove parent slug from Product permalinks.
New product permalinks will include only one (lowest-level) product category slug.

Primary Category Support

If you use an SEO plugin that lets you select a primary category (term), Permalink Manager automatically includes its slug in the default permalink.

Supported plugins include Yoast SEO, Rank Math, The SEO Framework, SEOPress, SmartCrawl, and All in One SEO Pro.

Example 1: Top-Level Primary Category Selected

If a top-level category such as "Sales" is set as the Primary Category, the custom permalink will contain only that term’s slug. Even if the post is also assigned to subcategories: "Europe" or "Switzerland", those terms will not be added to the custom permalink.

Top category selected

Example 2: Lowest-Level Primary Category Selected

If you choose a lowest-level term, such as "Switzerland" as the Primary Category, Permalink Manager will add the slugs of all its parent terms to the custom permalink.

This will also happen if no primary term is selected or if primary category support is disabled. In those cases, the plugin will use the lowest-level assigned term and its parents by default.

Lowest level term selected
If "Switzerland" is selected, Permalink Manager will follow the category hierarchy and append the slugs of parent categories ("sales/europe/switzerland") to the post permalink.

How to Disable “Primary Category” Support?

If necessary, you can turn off "Primary category" support in the plugin settings. Once disabled, the plugin will generate custom permalinks using the lowest category in the hierarchy, including its parent categories (when available).

You can disable "Primary category" support in Permalink Manager settings.

You can also turn it off with code:

add_filter( 'permalink_manager_primary_term', '__return_false' );

Advanced Customization & Developer Tips

How to Modify the Term Slug Programmatically

For advanced permalink customization, you can override the category slug used in the default custom permalink and modify it dynamically with custom code.

permalink_manager_filter_term_slug($slug, $selected_term, $post, $all_terms, $taxonomy)
Variable Description
$slug The slug or slugs trail used to replace %taxonomy% tag (eg. %category%) in default post permalinks (string)
Example input: europe/central-europe/slovakia
$selected_term Term object chosen to be used in the default permalink of a post (WP_Term)
$post The post object for which the default permalink is generated (WP_Post)
$all_terms Array of all terms that are linked to the post that the default URL is generated for (WP_Term[])
$taxonomy The name of the taxonomy (string)
Example input: category

Adding Multiple Top-Parent Categories

The example below shows how to use this feature to add the slugs of two top‑level categories to a single post permalink.

/**
 * The snippet changes the category slug used when default custom permalink is generated for a post
 */

function pm_multiple_top_categories_in_uri( $slug, $selected_term, $post, $all_terms, $taxonomy ) {
	// Only for 'category' slugs in 'post' permalinks
	if ( empty( $post->post_type ) || $post->post_type !== 'post' || $taxonomy !== 'category' ) {
		return $slug;
	}

	$top_terms = wp_filter_object_list( (array) $all_terms, array( 'parent' => 0 ) );
	if ( count( $top_terms ) < 2 ) {
		return $slug;
	}

	// Sort by name so the order is predictable, then use the first two
	usort( $top_terms, function ( $a, $b ) { return strcmp( $a->name, $b->name ); } );
	$slugs = wp_list_pluck( array_slice( $top_terms, 0, 2 ), 'slug' );

	return implode( '/', array_filter( $slugs ) );
}
add_filter( 'permalink_manager_filter_term_slug', 'pm_multiple_top_categories_in_uri', 10, 5 );

How to Auto-Update Permalink After Taxonomy Changes?

If no dedicated action hooks are available, you can also force Permalink Manager to regenerate the custom permalink after a category or taxonomy has been set using built-in set_object_terms hook.

The example below applies to WooCommerce products (with product categories), but you can modify the $taxonomy variable to apply it to other post types and taxonomies.

/**
 * Regenerates the custom permalink for a post when its taxonomy terms are updated.
 *
 * This hook can be useful when third-party plugins assign categories
 * or taxonomies *after* the post is created (e.g., during import or sync).
 * It ensures the custom permalink is updated to reflect the assigned terms.
 *
 * @param int $post_id The ID of the post being updated.
 * @param array $terms An array of term IDs.
 * @param array $tt_ids Term taxonomy IDs.
 * @param string $taxonomy Taxonomy slug (e.g., 'product_cat', 'category', etc.).
 * @param bool $append Whether to append the new terms to the existing terms.
 * @param array $old_tt_ids An array of old term taxonomy IDs.
 */
function pm_regenerate_product_permalink( $post_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ) {
	if ( $taxonomy === 'product_cat' && class_exists( 'Permalink_Manager_URI_Functions_Post' ) ) {
		$default_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri( $post_id );
		Permalink_Manager_URI_Functions::save_single_uri( $post_id, $default_uri, false, true );
	}
}
add_action( 'set_object_terms', 'pm_regenerate_product_permalink', 9, 6 );

Many plugins provide their own action hooks that are called after posts are created. For example, if you use Permalink Manager with Dokan, you can configure the plugin to generate a custom permalink after the dokan_new_product_added hook is called:

/**
 * Regenerates the custom permalink for a newly added product in Dokan.
 *
 * This function is hooked into Dokan's 'dokan_new_product_added' action, which fires
 * when a vendor creates a new product.
 *
 * @param int $product_id The ID of the newly created product.
 */
function pm_dokan_generate_product_permalink( $product_id ) {
	if ( class_exists( 'Permalink_Manager_URI_Functions_Post' ) ) {
		$new_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri( $product_id );
		Permalink_Manager_URI_Functions::save_single_uri( $product_id, $new_uri, false, true );
	}
}
add_action( 'dokan_new_product_added', 'pm_dokan_generate_product_permalink', 100 );

FAQ & Troubleshooting

No. Existing URLs remain unchanged until you regenerate them. Only new posts use the new URL format.

If you regenerate existing URLs, the plugin can automatically redirect the old URLs to the new ones with taxonomy slugs.

Why Are My Post URLs Missing the Category Slug?

If you see that new post URLs are missing the category, and a third‑party import or sync plugin is active, the plugin is probably saving the post too early (before it assigns the category). This is common in job board, directory, product sync, and bulk import plugins.

These plugins often change the way WordPress normally saves and publishes posts. Instead of completing the process in a single call, they split it into two steps:

  1. Firstly, they create the empty post using wp_insert_post() function, usually with only the title and content.
  2. Once the post has been saved and its custom permalink generated, they assign taxonomies, such as categories, and add metadata.

The same issue can occur when you create a post manually in the WordPress admin dashboard and publish it before assigning its categories.

Because the categories are not assigned until the second step, Permalink Manager cannot include them when it initially generates the custom permalink. This can result in incomplete URLs.

To fix this, you can add custom code to regenerate the permalink after the taxonomy terms have been assigned.

Is This Feature Available in the Free Version?

No, this feature is included in the free version as well. If you want to add custom taxonomy slugs to your custom post type permalinks, you do not need a Pro license.

You need Permalink Manager Pro if you want to change the URLs of custom taxonomy archives or use custom fields in your permalink structures.

Last updated on October 15, 2026 by Maciej Bis.

Go up