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'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
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
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
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


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.