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'm attempting to move some code from a plugin over to my theme's functions.php file, but when I attempt to wrap it in the is_single() wrapper inside of functions.php, it never fires. What am I missing?

if (is_single()) {
echo "hello world"; 
}

I can't get the echo to fire from any inside post page.

This has to be something insanely simple I'm overlooking.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

All that I can think of is to verify that you are in fact on a single post page ( echo out an else conditional, make sure that you are actually hitting your block of code ).

if ( is_single() ) {
    echo 'Hello World, Is Single';
} else {
    echo 'Not Single';
}

Where exactly are you placing the code (Header, Body, Footer, which template file)? Are you using any frameworks like Carrington ?

share|improve this answer
    
I'm calling is_single from inside of functions.php. I believe I have to place it inside a function and call the function from an add_action statement. –  Scott B Jan 7 '11 at 19:30
    
For example, this is the only way I can get it to work > add_action('template_redirect', '_my_function'); –  Scott B Jan 7 '11 at 19:31
1  
Yes, calling it after the template_redirect action is the only way it will work. If the plugin called it directly, it was doing it wrong. –  scribu Jan 7 '11 at 19:38
1  
Just think about where in the script you are calling is_single(). If you add is_single to an an action ( eg template_redirect ) it will be called when that action is fired, make sure that the $wp_query object is available at that point. If you call is_single from a function that is on a template that is defined in your functions file you should be fine. –  Jonnybojangles Jan 7 '11 at 19:45

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.