Removing “Search this site” from the search block in Drupal 6

January 25, 2009

Recently I wanted to remove the label “Search this site:” from Drupal 6′s search block, preferably without resorting to any hacks such as parsing a text string for “Search this site:” (which could break whenever a new minor Drupal release gets out) or hiding the label in CSS (while this is not the worst solution, I always prefer not to output any unnecessary markup). Placing the following function in template.php seems to do the trick in a clean way.

function phptemplate_preprocess_search_block_form(&$variables) {
        unset($variables['form']['search_block_form']['#title']);
        unset($variables['form']['search_block_form']['#printed']);
        $variables['search']['search_block_form'] = drupal_render($variables['form']['search_block_form']);
        $variables['search_form'] = implode($variables['search']);
}

The variable $variables['form']['search_block_form']['#title'] contains the string “Search this site:” or its translation, but gets rendered as a label – fortunately simply unsetting it removes the label altogether! I am not sure why $variables['form']['search_block_form']['#printed'] also needs to be unset, but if that line is omitted, the text box (input field) won’t show up.

  • Anonymous

    hey dude, try this:
    function my_theme_search_block_form($form) {

    unset($form['search_block_form']['#title']);
    return drupal_render($form);
    }

    • Claus

      I’m gonna try your solution the next time I need this.
      Meanwhile for those with a more pragmatic approach to their markup than me I’d like to throw in Zen’s solution:
      #edit-search-theme-form-1-wrapper label /* Label that says “Search this site:” */
      {
      display: none;
      }

      • Nurjanka


        … “{
        display: none;
        }

        It doesn’t work :(

        • Nurjanka

          I do not understand why this is so problematic ?

  • Anonymous

    hey dude, try this:
    function my_theme_search_block_form($form) {

    unset($form['search_block_form']['#title']);
    return drupal_render($form);
    }

    • claus

      I’m gonna try your solution the next time I need this.
      Meanwhile for those with a more pragmatic approach to their markup than me I’d like to throw in Zen’s solution:
      #edit-search-theme-form-1-wrapper label /* Label that says “Search this site:” */
      {
      display: none;
      }

  • Manoj

    try this:
    just edit the base search module,In module file search 'Search this site' and delete it.,,,,

  • Claus

    While this is easy to do, the problem is you have to repeat it after each Drupal version update.

Next post: