What's the best way to remove the search form from the search result page in Drupal 8?

  • Is the form a block? You can disable the path visibility for search result paths.
    – Kevin
    Oct 12, 2017 at 19:26
  • 1
    No, it is not a block. There is a search form that is a block and I have that placed in a region. By default the search results page has a second search form that is not a block and there is no way to hide it from the admin. I don't want to have this second search form. Oct 12, 2017 at 19:28

3 Answers 3


There is not much you can customize in core search. So you probably need to override Drupal\search\Controller\SearchController::view and remove this line:

  $build['search_form'] = $this->formBuilder()->getForm(SearchPageForm::class, $entity);

Put your extended class into the route search.view_node_search in a RouteSubscriber.

But I don't think it's worth the effort. You can either simply hide the form in CSS or if you want a fully customizable search solution use Search API.


I had the same question for Drupal 9 and first I hid it with css, then I found it can be disabled in /admin/config/search/pages/manage/node_search

Uncheck: Display basic search Display advanced search


I'm not sure if is the best way, but you can remove it from your theme preprocess, just for that page: /** * Implements hook_preprocess_search_api_page() */ function YOURTHEME_preprocess_search_api_page(&$vars) { unset($vars['form']); }

  • This does not appear to work. Using hook_preprocess_HOOK() would be something like YOURTHEME_preprocess_page__search_api(&$vars) {}. That assumes the hook suggestion would be search_api, which I'm not certain it is. Furthermore, I think $vars['form'] would not be the correct array key to unset b/c the form would likely be found within a nested array starting with the page region name as the first key.
    – Jason
    May 15, 2018 at 13:23

Your Answer

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

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