How to Check if Category is a Subcategory

This is a useful function I use for building conditional statements to check whether a category is a subcategory (.e. has a parent).

In your functions.php file insert the following:

Then in your theme you can use the conditional as follows:

If you enjoyed this post, make sure to subscribe to WPMayor’s RSS feed.

About Jean Galea

Jean Galea is a WordPress developer, podcaster and entrepreneur. He is the founder of WP Mayor and WP RSS Aggregator. His personal blog can be found at jeangalea.com. Check out his podcast focused on doing business with WordPress over at Mastermind.fm.