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, entrepreneur and padel player. He is the founder of WP Mayor, the plugins WP RSS Aggregator and EDD Bookings, as well as the Mastermind.fm podcast. His personal blog can be found at jeangalea.com.