WordPress is_home() conditional tag

I use the is_home() conditional tag to control when my ads show up. I prefer to only have my ads show up when single posts are viewed. Helps keep my home page looking clean and relevant.

Currently, I have my ads setup to show on all pages except for my home page. To get the same functionality setup on your WordPress simply wrap your ad codes with the code below.

<?php if ( !( is_home() ) ) { ?>

[your ad codes go here.... ]

<?php } ?>

ALternatively if you want your ads to only show up on your home page,

<?php if (  is_home()  ) { ?>

[your ad codes go here.... ]

<?php } ?>

If you use static pages for your home instead, then replace is_home() with is_front_page() .

Try it out, drop me a note if you need help.

9 Responses to “WordPress is_home() conditional tag”

Author comments are in a darker gray color for you to easily identify the posts author in the comments

  1. shaxx says:

    that is great but then would that affect your earnings from the ads if nobody goes to the single post?

  2. abi says:

    This is brilliant man! Thanks danny for helping me out on mine! Nice n clean now ;)

  3. Danny says:

    Abi, no probs bro. :D

    Shaxx, actually most people I feel go directly go to single posts. If they search on goolgle, most likely the result will point to a single page.

    But anyways, I’m not much of a ads person. As long as it pays for my hosting I’ll be happy :D

    O ya, it also makes the site look nicer in screenshots without the ads ;)

  4. Wing Loon says:

    Awesome. I am looking for this too and a new theme, :)

  5. Danny says:

    No probs WL. I’m on a WP sould search now ;) . I’ll share more soon…

  6. Danny says:

    No probs WL. I’m on a WP soul search now ;) . I’ll share more soon…

  7. SarahG says:

    is_single() will work too and more efficiently as it means that if you happen to use the index page for anything other than the front and single post pages then you’re targeting just the one page.

    If you started to use the index page for your category pages too you’d need to add more conditionals in.

    Handy bookmark – http://codex.wordpress.org/Conditional_Tags

  8. Danny says:

    Thanks for the tip Sarah.

  9. ravi says:

    very useful tip. thank you

Leave a Reply

© 2008-2009 The Danesh Project
Powered by Wordpress and made by Guerrilla. Best viewed in Mozilla Firefox