Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

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
}
share|improve this answer
add comment

Your Answer

 
discard

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.