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

I have this structure

Category > Subcategory > Post

I´m trying to display some content if the user it´s on a specific category, or in it´s subcategory or post.

I´m using this code but it only works if the user is in the category.php, not if the user it´s on a single.php that belongs to the that parent category:

    <?php if(is_category('catering')){?>
        <div class="logo">
            <img src="<?php bloginfo('template_directory') ?>/images/canal.png" />
        <div class="carta_catering">
    <?php    }  ?>

I tried with if(in_category) but it still didn´t show anything on single.php.

Any ideas?

share|improve this question

The is_category Conditional Tag checks if a Category archive page is being displayed - hence it is expected to return false on single post pages, whether the post in question is in said category or not.

To check for the latter condition, make use of has_category. If you want the content to show up on category as well as single post pages (in the category), combine the two:

if ( is_category( 'catering' ) || has_category( 'catering' ) ) {
     // display something
share|improve this answer
it still doesn´t show anything on the single post :( – wpuser Nov 21 '12 at 10:50
maybe i`m putting wrong the syntax, I don´t know – wpuser Nov 21 '12 at 10:51
if ( in_category( 'catering' ) && is_single() ) {

This will return true on single posts in the category catering but NOT the category archive page.

if ( in_category('catering') && is_single() || is_category('catering') ) {

This returns true on all single posts in the category catering and the category archive page for catering.

if ( in_category('catering') ) {

This ALSO returns true on all single posts in the category catering and the category archive page for catering.

Couldn't find anything in the Codex for sub categories.

I would try the sub category i.d with the category conditional tag to see if it returns true for posts in a sub category.

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.