WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have is_category() for categories, however I m not getting a conditional tags for subcategories, I want to enqueue script only on subcategories but on the parent. So lets say I have a parent category 'fun' which has several sub categories like 'stories', 'arts', 'crafts' . How do I load script only for the subcategory but not for parent 'fun'?


share|improve this question

You can check if a category has a parent, if it does it is a child category.

if( is_category() ){
    $this_category = get_queried_object();
    if( 0 != $this_category->parent ){
        echo 'category has parent';
share|improve this answer

[Unlike is_category()] in_category() tests only against a post's assigned categories, not ancestors (parents) of those categories.

Testing if a post is in a descendant category

So, in_category is probably what you are after.

Based on the example cited in your question, you'd do something like this:

if( in_category( array( 'stories', 'arts', 'crafts' ) ) ) {

    // Do what you want...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.