Support » Fixing WordPress » Widget breaks search

  • Hello, here’s the code I’m using.

    <?php
    $searchtext = get_search_query();
    if($searchtext == ''){ $searchtext = 'Search...'; }
    ?>
    <div id="search"><form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
      <div>
        <input type="text" value="<?php echo $searchtext; ?>" name="s" id="searchfield" onfocus="if (this.value==this.defaultValue) this.value='';" />
        <input type="image" src="wp-content/themes/active/images/go.jpg" id="searchsubmit" value="Search" />
      </div>
    </form></div>
    
    <div class="sidedivider"></div>

    When I put it in the sidebar.php file, it works fine. When I copy the same block to a new Widget (via the text option, then pasting it in) the search completely breaks.

    Is this because I’m putting PHP in one of these? Is there a way to fix it?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • try adding the widget “search” on the sidebar instead of a widget “text”, then you can create an searchform.php file on your theme and put your code on it.

    Thread Starter Philljc

    (@philljc)

    That fixes the search and kind of defeats the purpose of having it as a custom widget, and there are other PHP widgets I need to use

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Widget breaks search’ is closed to new replies.