Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have CSS issues with a certain div only on the front page (front-page.php). As I can't fix it, I was thinking about removing the item, but only on the front-page.

I'm not exactly sure how I have to code this in Wordpress.

I want this div in the Header to show up everywhere but on the front-page.php:

<!-- BEGIN TOP SEARCH -->

<form id="searchform" action="<?php bloginfo('url'); ?>/" method="get">
                    <input type="submit" value="" id="searchsubmit"/>
<input type="text" class="field" name="s" id="s" value="Search or be lost" onfocus="this.value=''" />

                </form>
            </div>
            <!-- END TOP SEARCH -->

Is this possible?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

I think japanworm do not want it on the frontpage, the code above let's it display only on the frontpage.

You can exclude something (if not) by putting an ! before the tag. What you want to say is:

If it isn't front page than display the form

So it would actually be

<?php if( !is_front_page() ) { //if we are not on the front page ?>
the code of your form
<?php } ?>
share|improve this answer
    
That's it! Thank you so much! :) –  japanworm Jul 22 '13 at 13:29

You want is_front_page

if (!is_front_page()) { ?>
  <!-- BEGIN TOP SEARCH -->

    <form id="searchform" action="<?php bloginfo('url'); ?>/" method="get">
      <input type="submit" value="" id="searchsubmit"/>
      <input type="text" class="field" name="s" id="s" value="Search or be lost" onfocus="this.value=''" />
    </form>
  </div>
  <!-- END TOP SEARCH --><?php
}

Take a look at the list of Conditional Tags. It is all in the Codex.

By the way, there is a stray </div>. That may be why this markup doesn't work the way expect.

share|improve this answer
    
No, it's part of a bigger div, so that has nothing to do with it. The end comment should probably be before the div. I know about the conditional tags, but I wasn't sure how to implement it. And I'm really thankful for your help, but if I use the code you provided then my side suddenly doesn't load anymore. No error message. Just doesn't load anything anymore. :( –  japanworm Jul 22 '13 at 13:20
    
Actually I got your code to work, but it has the opposite effect of what I want! It's only shown on the front page now. –  japanworm Jul 22 '13 at 13:25
1  
Fixed. Should have had a ! –  s_ha_dum Jul 22 '13 at 13:31

Your Answer

 
discard

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.