2

I'm working on customizing my search results page. By default, the results page contains another instance of the search box at the top. I have the search box in a block at the top of every page, so it's just cluttering things up on the results page. I have already overridden the two template files, but I don't see anything in there that outputs the second search box. How can I remove it?

2 Answers 2

1

Here's a simple approach to work within your theme, without requiring a dedicated module:

add to your template.php file...

function YOURTHEME_page_alter(&$page)
{
  if (arg(0) == 'search')
  {
    if (!empty($page['content']['system_main']['search_form']))
    {
      hide($page['content']['system_main']['search_form']);
    }
  }
}
1
  • Beauty. This is exactly what I was looking for! Simple solution, too. I'm sure @coreyp_1's solution would work as well, but I didn't want to have to make a full module. Thanks to both answerers!
    – eljefejb
    Commented Jul 14, 2014 at 18:36
4

This is a fun one... The Search box is returned as part of the render array returned by search_view().

I suggest that you make a hook_menu_alter() which replaces the default callback for the search page with your own, which is basically a pass-thru to the core function, but that unsets the search form. Something like this:

function MYMODULE_menu_alter(&$items) {
  $items['search']['page callback'] = 'MYMODULE_search_view';
}

function MYMODULE_search_view($module = NULL, $keys = '') {
  $build = search_view($module, $keys);
  unset($build['search_form']);
  return $build;
}

Don't forget to clear your cache to pick up the new hook and menu changes.

You may need to add additional paths to the hook_menu_alter() as needed (e.g., if you search users, then you may need to add entries for search/user and search/user/%menu_tail).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.