Condition function for is parent category?

I have a parent category with many sub-categories and I am trying to display the page differently when it is in that specific parent category.

But instead of writing the code like is_category(‘parent’, ‘sub-1’, ‘sub-2’)…etc, is there an easy way to say if it is in the parent category it is true?

1 Answer
1

I’m not sure I fully understood your question, but wrapping a function inside a new function will make it shorter. For example, do the following in your functions.php file:

function is_parent($slug){
   if(is_category($slug)){
       return true;
   }else{
       return false;
   }
}

And then simply use it like:

if(is_parent('slug')){
    // do something
}

Leave a Comment