WordPress Permalinks with Multiple Categories

WordPress Permalinks with Multiple Categories

Creating complex URLs has never a been a great strength of WordPress.

For example, for a long time, it was recommend that you shouldn’t include categories in your URLs because of performance issues.

However, the WordPress team have been making improvements on this, and now it’s possible to include not just one, but multiple categories inside a URL. In this tutorial, we’ll show you how to make that happen.

Step 1. Organize your categories

  • Go to Posts > Categories
  • Set up your categories so that they are organized in a hierarchy like in the image below. You do this using the “Parent” option for each category.
media_1390488302433.png

Step 2. Permalink structure

  • Go to Settings > Permalinks.
  • Add the category to your Permalinks. You can do that by using this set up: /%category%/%postname%/
media_1390488580718.png

Step 3. Add only one category

  • Go go to a post and look for the Categories block.
  • Choose one and only one category. The reason, WordPress will stop creating the URL as soon as it finds a category in the hierarchy hierarchy.

For example, choose category 3 …

media_1390488492510.png

And you get this URL with all of the categories, including 3:

media_1390488744806.png

However, if you choose both 2 and 3 …

media_1390488800931.png

Then WordPress stops creating the URL after 2:

media_1390488841054.png

Instructor

  • Steve is the founder of OSTraining. Originally from the UK, he now lives in Sarasota in the USA. Steve's work straddles the line between teaching and web development.

0 0 votes
Blog Rating
Subscribe
Notify of
12 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Jean Hugues Bretin

Excellent article, thanks a lot! It helped me understand why my url structure was not matching my selected categories in Avada theme.

Daniel

Tnax for this info, but i have a question. When i use it like this i get the correct url (toplevel/second/third/postname). But then the wp-list categories only shows the third level

Abhi

Basically, I’d like to create a category permalink like example.com/books/adventure where both “books” and “adventure” are two separate categories. rather than to make adventure a child-category of books.
Is there a solution for this?

manideep

Thanks a lot! It helped me lot

mikall

Awesome!  So glad you found OST and that we were able to help!

Kevin McQuaid

What do you do if  you need the post in two categories? I have a post to go in Brexit and News. I created the post with a category of Brexit and the permalink used Brexit as I wanted. I then added the category of News and the permalink changed to News. 

If I try it the other way and create the post as a news category first then the permalink is created as News but when I add the Brexit  category it remains as News.

Both the News and Brexit categories are on the same level as each other in the categories structure (ie one is not a sub category of the other.)

mikall

You would need a Top Level category and a sub level category in order to get it in both categories.  For example: If News was your Top Level category and Brexit was the subcategory, then you would select the Brexit category for the post and the permalink would include the Top Level (news) and the subcategory (brexit).

Mark

But… the title says “WordPress Permalinks with Multiple Categories” and step three is “Choose one and only one category.”

Thats like looking for an article on adjusting a carburetor and the post saying “Buy a Tesla”

mikall

Mark – it’s true that you are to select just one category and that is because the URL will include that one plus every other category underneath it that one thus giving you multiple categories in your URL.  If you choose more than one, it will only get the top one selected, plus the ones beneath it that were NOT selected.  Check over the sample url images in Step 3 to see what I’m talking about.  The key is to only select 1 (the top) category in order to get all of the others categories below it (you get multiple categories in your URL by only selecting the top category) – Make sense?  

Neo

Just know that a post cannot have multiple permalinks in the end–it is not supported in WordPress as far as I know. With Yoast SEO plugin (if used), in addition to selecting multiple categories, you can select one as “primary”. The permalink will be generated based on that primary category. Let’s say you put “my-post” into category Top Level, 1, 2, and 3 below, then make 1 primary:

Top Level
– 1 (primary)
— 2
— 3

Then your permalink for it will be /top-level/1/my-post/. Hope this helps!

Winnpeg

Thanks for this great article. It helped me and my guys at [color=#000000]webgigg.[/color]

Dan

Thank you so mutch!

12
0
Would love your thoughts, please comment.x
()
x