I am trying to run a code only in blog posts, and another code only in single pages. But I can't even make a single working php if statement, that contains a wordpress conditional tag.

In footer.php, I tried to make some simple functions

if( is_singular() ) {
    // should show work in singular pages, bot is not working

In the below code, the code4 get's executed, on the front page

if ( is_front_page() && is_home() ) {
} elseif ( is_front_page() ) {
} elseif ( is_home() ) {
} else {

Can you please tell me what am I doing wrong? And how can I make some codes only for blog posts, and some only for single pages?

1 Answer 1


It’s just that you got it a bit wrong - it’s actually


(not singular). If you want to address pages in general (not posts I assume), you would use


. If you need to address a specific page you could use its ID like so


where 13 would be the ID of the page. But you have a lot of options - see http://codex.wordpress.org/Conditional_Tags .

However, of course you can use conditional tags in both header and footer (i.e. outside the loop) to tailor your template better ;).

  • If you are unsure of how to correctly form PHP just take a look at the examples, it is a bit tricky at first, but you’re getting used to it.
    – physalis
    Feb 20, 2015 at 23:50
  • It's not that, I tried other conditionals, but they all return negative.
    – Marian07
    Feb 21, 2015 at 9:57
  • So, none is actually working? Can you try putting up <?php if(is_single()) { echo 'This is working!'; } ?> into your footer.php and see whether it is being shown on the website/in the source code?
    – physalis
    Feb 22, 2015 at 21:49

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.