This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

WordPress 5.0 is out. Test all the great new features before upgrading your Live website. Read How!

Get Categories and Subcategories In WordPress

Updated on  17th May

2 Min Read
WordPress Get Category
Reading Time: 2 minutes

The the_category() template function is often used in WordPress theme development. It displays the parent category and any child categories. In several instances, this function could generate a long list. The problem becomes important when a website has a large number of categories and subcategories. In such WordPress get category cases, the_catagory() function often create a huge list that is often less than useful for the task.

Get Specific Post Category

The following code will get the category of a specific post. Please note that you have to add this code to either content-single.php or single.php

Get Subcategory From Parent Category

First get the subcategory from the parent category for particular post. Next, add the following code in the post template where the index and archive post loop start. You could also add this code after the title.

Name Of Category Get By Id

Description Of Category (Through ID)

Category slug is the URL name of that category:

Description Of Category (Get By Slug)

Category slug is the URL name of that category:

Category Link (Get By ID)

You can generate a link to a particular category using the id. Use the following code:


In this article, I discussed how to get specific post category, sub category from parent category, category name by ID, category description by ID and category link by ID.

If you need help with the code or would like to add to the discussion, do leave a comment below.


Share your opinion in the comment section. COMMENT NOW

Owais Alam

is the WordPress Community Manager at Cloudways - A Managed WooCommerce Hosting Platform and a seasoned PHP developer. He loves to develop all sorts of websites on WordPress and is in love with WooCommerce in particular. You can email him at

Be the first to check out WordPress 5.0

Use our Staging feature before upgrading your website to WordPress 5.0.

Get Our Newsletter
Be the first to get the latest updates and tutorials.