Adding a seach bar to your WordPress blog without using a widget

//Adding a seach bar to your WordPress blog without using a widget

Adding a seach bar to your WordPress blog without using a widget

Sometimes you want to add a search bar but not as any widget.  I found this on the WordPress Forum. I used it, it worked like a charm. Thought I’d pass it along.

Put this in the php file where you want your search bar to go:

<form method=”get” id=”searchform” action=”<?php bloginfo(‘home’); ?>/”>
<div><input type=”text” size=”18″ value=”<?php echo wp_specialchars($s, 1); ?>” name=”s” id=”s” />
<input type=”submit” id=”searchsubmit” value=”Search” />
</div>
</form>

2 more helpful things:

1. if your template supports it you can just add :
<?php include (TEMPLATEPATH . ‘/searchform.php’); ?>

2.adding the following code will put a text inside the search box.
(like “Write your search and hit Enter” )

<form method=”get” id=”searchform” action=”<?php bloginfo(‘home’); ?>/”>
<div><input type=”text” size=”put_a_size_here” name=”s” id=”s” value=”Write your search and hit Enter” onfocus=”if(this.value==this.defaultValue)this.value=”;” onblur=”if(this.value==”)this.value=this.defaultValue;”/>
<input type=”submit” id=”searchsubmit” value=”Search” />
</div>
</form>

and finally, combining those two advices, just save the code from part two as searchform.php in your template folder, and you can always call it with method number 1.

By | 2011-12-02T00:00:26+00:00 December 2nd, 2011|Web Design Articles|2 Comments

About the Author:

2 Comments

  1. Fred293 December 17, 2011 at 9:16 am - Reply

    Awesome! Thanks!

  2. Erik October 28, 2012 at 9:23 pm - Reply

    Thanks, That was super helpful!

Leave A Comment