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.
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%/
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 …
And you get this URL with all of the categories, including 3:
However, if you choose both 2 and 3 …
Then WordPress stops creating the URL after 2:
Excellent article, thanks a lot! It helped me understand why my url structure was not matching my selected categories in Avada theme.
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
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?
Thanks a lot! It helped me lot
Awesome! So glad you found OST and that we were able to help!
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.)
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).
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”
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?
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!
Thanks for this great article. It helped me and my guys at [color=#000000]webgigg.[/color]
Thank you so mutch!