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 am using this code to show ad below single post but only if it is in specified category. Code is giving right out put but it is also showing up on archive pages. I just want to show on single post pages.

function demo_link() {
        if (in_category('themes')) { ?>
     Some code
    <?php } else { ?>
    Some code
    <?php
        }
    }
    add_action('thesis_hook_after_post_box', 'demo_link');
share|improve this question
add comment

1 Answer

If you mean a single post, not a page then use the conditional tag is_single() and check for this, like:

function demo_link() {

    if ( is_single() && in_category( 'themes' ) ) {
        // Some code #1
    } else {
        // Some code #2
    }
}
add_action( 'thesis_hook_after_post_box', 'demo_link' );

If you will use it on page, static post type from WP, then use is_page() or use is_singular() for post and page. The current example check for post and if in category 'themes', the output 'Some code #1' or if not this conditional statement, the output 'Some code #2'.

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.