I'm trying to display content depending on if a user is in a category or a single post.

The function i'm using if this is a category is:

<?php if (is_category('')) { ?>

Similarly the function i'm using if this is a single post is:

<?php } elseif (is_single($post)) { ?>

How can I join these 2 functions creating a single function call to say if this is any category OR any single post?


If this is the same if/else, you can just combine into if ( is_category() || is_single() ). You don't need to pass anything to is_category() or is_single() most of the time, unless you are looking for a category or post in particular.

| improve this answer | |
  • 2
    Exactly right. if ( is_category() || is_single() ) will return true if the current page is a Category Archive Index or a Single Blog Post. – Chip Bennett Jun 28 '11 at 0:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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