Remove parent slugs from WordPress permalinks

It is sometimes advantageous to have shorter URLs for better SEO performance. Removing the parents’ slugs from children permalinks may be an effective way to do this. However, if you are not acquainted with the WordPress codebase, this might be a complicated process. This is where Permalink Manager comes in handy, allowing you to easily shorten WordPress permalinks.

New permalink formats and existing permalinks
The parent slugs will be automatically removed from all new post URLs. Existing URLs will need to be regenerated if you want to use the new formats on them too. You will find step-by-by-step instructions on how to do this in this post.

As a general rule, if you use Permalink Manager to add a slug of hierarchical taxonomy terms to custom post type permalinks, the plugin will respect the hierarchy tree. In other words, if a term assigned to a certain post contains a parent term, Permalink Manager will include not only the given term’s slug but also its parents. Click the button below to find out how to add a taxonomy slug to your post permalinks.

How to add taxonomy slugs to post permalinks?
In this article, you can find detailed instructions on how to add the taxonomy slugs to post permalinks.

Hierarchical and non-hierarchical post types and taxonomies

WordPress allows you to register either hierarchical or non-hierarchical content types. If none of these names seems familiar, have a look at the built-in content types. Pages and categories are both hierarchical in the sense that they may have either a parent or a child. If you look at the example below, the content hierarchy should be obvious.

http://example.com/americas/
http://example.com/americas/north-america/
http://example.com/americas/north-america/canada/

"Page" is a inbuilt hierarchical post type

At the same time, non-hierarchical posts and post tags are impossible to arrange in a “hierarchy tree”. As you can see, their URLs are “flat” and do not include any parent slugs.

http://example.com/how-to-add-php-snippet-to-wordpress/
http://example.com/change-author-pagination-base-in-wordpress/
http://example.com/6-seo-tips-for-better-wordpress-permalinks/

"Post" is a non-hierarchical post type

How to remove parent slugs from post permalinks?

We shall demonstrate these instructions using a simple example to help you understand them. As you can see below, the custom post type permalinks (“car”) are hierarchical.

Original permalink format
http://example.com/%car%/
http://example.com/car/ford/ford-fiesta/
http://example.com/car/jeep/jeep-wrangler/

Our goal is to get rid of the parent slugs that are attached to them.

New permalink format
http://example.com/%car_flat%/
http://example.com/ford-fiesta/
http://example.com/jeep-wrangler/

The steps are straightforward; if you want to eliminate the parent slugs and make the hierarchical post types “flat” go to the “Tools -> Permalink Manager -> Permastructures” section. Now, scroll down to the post type you wish to update and change its permastructure settings. By default, the permastructure tag for posts, pages, or custom post types slugs will be %postname% (for posts), %pagename% (for pages), or the name of the custom taxonomy, e.g. %car%.

You will need to add the “_flat” suffix to the permastructure tags if you only want to include the actual post slug in the permalink and not the parent slugs. Thus, the tags should look like this: %postname_flat%, %pagename_flat%, or %car_flat%.

Remove parent slugs from "Cars" permalinks
The %postname_flat% permastructure tag is universal and can be used for all post types.

How to include only one term slug inside post permalinks?

The instructions below may be helpful if you want to add a single term slug to post permalinks but not the whole trail including their parent terms. If the linked taxonomy was hierarchical, and you want to keep the post permalink short, you may set Permalink Manager to skip the parent slugs automatically.

Depending on your requirements, you may either add a single slug of the highest-level parent or the lowest-level child. To use just the top parent slug, append the suffix “_top” to the end of the taxonomy permastructure tag (for example, replace %product_cat% with %product_cat_top%). In the latter, the suffix should be “_flat” (for example, replace %product_cat% with %product_cat_flat%).

Original settings
http://example.com/%product_cat%/%product% (Original permalink format)
http://example.com/clothing/t-shirts/cotton/happy-ninja
http://example.com/clothing/jackets/leather/biker-black

New permalink format with top-parent term slug only
http://example.com/%product_cat_top%/%product%
http://example.com/clothing/happy-ninja
http://example.com/clothing/biker-black

New permalink format with lowest-child term slug only
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.

Original permalink format
http://example.com/%car-brand%/
http://example.com/car-brand/korean/hyundai/
http://example.com/car-brand/european/volvo/

New permalink format
http://example.com/%car-brand_flat%/
http://example.com/hyundai/
http://example.com/volvo/

You may remove parent slugs from taxonomy permalinks in the same way that you removed them from post permalinks. Simply replace default tags: %term% or %custom_taxonomy_name% with %term_flat% or %custom_taxonomy_name_flat% in the permastructure settings.

Remove parent slug from taxonomy permalinks
Similarly to the %postname_flat% tag for post type permastructures, the %term_flat% tag may be used for any taxonomies.
Go up