WordPress comes with two built-in taxonomies to sort your content. They are called categories and tags.
As you probably know, categories are typically used for more broader topics and can have subcategories. However, if you are using the default WordPress URL structure, then your categories and subcategories are not included in the post URLs by default.
Some websites use categories and subcategories in WordPress URLs for their posts. Some websites that use subcategories (like this one) display both parent and child categories in the URL.
Including category or subcategory to your post URLs makes them more user-friendly. It matches the breadcrumb navigation on your site and it includes more keywords and text which is also helpful for SEO. Having said that, let’s see how to easily add category and subcategory in WordPress URLs.
Adding Category and Subcategory in WordPress Post URLs
First, you need to visit Settings » Permalinks page in your WordPress admin. There you need to click on the ‘custom structure’ option under common settings area.
Next, you need to add /%category%/%postname%/
in the field next to custom structure.
After that, don’t forget to click on the save changes button to store your settings.
That’s all WordPress will now start including category and subcategory in WordPress URLs. You can see this in action by editing a post or creating a new one.
File that post under a category (and subcategory if you use them) and click on the update button.
You will notice category and subcategory included in the post’s permalinks.
Using Multiple Categories or Subcategories
Let’s suppose you file your blog posts into multiple categories or subcategories. WordPress will only include one category and one subcategory in the URL. If you didn’t choose a subcategory, then it will only show one parent category.
WordPress chooses the category alphabetically. For example, if you file a post in Apple and Technology categories, then WordPress will include apple in the URL because it comes first in alphabetical order.
http://example.com/apple/article-title-here/
If you file a post in ‘Apple’ and a subcategory under that called ‘Technology’, then it will include both of them in the URL.
http://example.com/apple/technology/article-title-here/
If you selected a subcategory but didn’t specifically select parent category, then WordPress will still include parent category in the URL.
Another scenario is when you have a parent category, subcategory, and a sub-subcategory. WordPress will include all three of them in the URL.
http://example.com/apple/technology/events/article-title-here/
We hope this article helped you learn how to include category and subcategory in WordPress URLs.