Skip to main content

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');
  } 
}
register_widget("BE_Custom_Search_Widget");

Looking for Expert WordPress or Drupal development?

I am a freelance website developer and designer based in the UK. I work as a remote Drupal developer, WordPress developer and Front-end developer for a variety of startups, charities and international businesses in Bristol, Bath, London and Europe. You can learn more about me by visiting my resume page.

Get in touch for a free quote on your next project and if you want to connect me with then check out my LinkedIn profile.