0

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?

2 Answers 2

1

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 } ?>
0
1

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.

3
  • 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
    Commented Jul 22, 2013 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
    Commented Jul 22, 2013 at 13:25
  • 1
    Fixed. Should have had a !
    – s_ha_dum
    Commented Jul 22, 2013 at 13:31

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.