WordPress Tutorial: Simple Search Widget

WordPress offers some decent widgets out of the box, but annoyingly the search widget uses the same form as the main search block usually found in a themes header.

Using the following technique it is quite easy to use a custom search form within a widget so you can customize the functionality, and look and feel without having to compensate for a search box that may occur in more than one place.

class BE_Custom_Search_Widget extends WP_Widget {
  function BE_Custom_Search_Widget(){
    $this->WP_Widget('BE_Custom_Search_Widget', 'Custom Search Widget');

  function widget($args, $instance) {
    include (TEMPLATEPATH . '/searchform.php');