if (is_single()) {
    echo '1';

} elseif ( is_page() ) {
    echo '2';

} else {
   echo '3';


I put this snippet at the top of index.php, which is what I'm using to govern the layout of my blog post feeds. I then created a new page, set template to default, and left it blank. It shows all of my posts. But the snippet above echoes a 3. It's using index.php as the template, but it's a page. Why isn't it echoing 2?


Since the blog feed page was set in Settings > Reading, I had to use the conditional is_home();. Apologies for all of the confusion.

2 Answers 2


Conditional tags mostly derive from and rely on main query.

  • is_page() function calls
    • $wp_query->is_page() method
      • which checks $wp_query->is_page property (set during load) and some more stuff if you asked to check for specific page.

So the likely reason for conditional tag not to produce expected return is issue with global $wp_query, for example it getting erased and overwritten with query_posts() call.

  • To that effect, you may wish to echo get_the_ID(); and see if it matches with the ID that appears in the link when you hover over the Edit Page(Post) link.
    – GhostToast
    Commented Jun 18, 2013 at 18:00
  • @GhostToast - echo get_the_ID(); was blank. <?php the_ID(); ?> displayed the post number of the first post that shows up in the feed, but not the ID of the feed page itself. Commented Jun 18, 2013 at 18:09

Expanding on @Rarst answer, you will need to run a wp_reset_query() or wp_reset_postdata() at the end of your loop (feed). This will set the global variable $wp_query back to what it should be, and your conditionals should work as intended.

  • Tried both. It's still echoing a 3. Commented Jun 18, 2013 at 18:13
  • 1
    Show us your full code please.
    – GhostToast
    Commented Jun 18, 2013 at 18:14
  • Just a standard post-displaying page Commented Jun 18, 2013 at 18:20
  • If that were true, you wouldn't be here
    – GhostToast
    Commented Jun 18, 2013 at 18:22
  • I assure you, it is. Just a normal page that gets posts, calls the header and footer, and not much else. I updated my original post above to explain why I was having this problem. It was an oversight on my part, because of a setting in Settings > Reading. Commented Jun 18, 2013 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.