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 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
    add_action('thesis_hook_after_post_box', 'demo_link');
share|improve this question

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

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.