WordPress is_home() conditional tag

14 Aug, 2008  |  Posted by Danesh  |  in Blogging, HowTo, WordPress

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.

  • Digg
  • del.icio.us
  • BlinkList
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Furl
  • Google
  • Live
  • Facebook
  • Pownce
  • TwitThis
  • E-mail this story to a friend!
Tags: , , ,

8 Responses so far | Have Your Say!

  1. shaxx  |  August 14th, 2008 at 7:02 pm #

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

    shaxx - Gravatar
  2. abi  |  August 14th, 2008 at 7:18 pm #

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

    abi - Gravatar
  3. Danny  |  August 14th, 2008 at 10:09 pm #

    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 ;)

    Danny - Gravatar
  4. Wing Loon  |  August 14th, 2008 at 11:32 pm #

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

    Wing Loon - Gravatar
  5. Danny  |  August 15th, 2008 at 8:36 am #

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

    Danny - Gravatar
  6. Danny  |  August 15th, 2008 at 8:36 am #

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

    Danny - Gravatar
  7. SarahG  |  August 15th, 2008 at 3:51 pm #

    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

    SarahG - Gravatar
  8. Danny  |  August 15th, 2008 at 4:34 pm #

    Thanks for the tip Sarah.

    Danny - Gravatar

Leave a Feedback

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>