How To Change No Search Results Text In Drupal 6

Every Drupal project I finish will usually have the same request at some point. This usually happens when the client tries to do a search that produces no results and sees the search hinting text about blue smurfs.

The text about blue smurfs that is printed when there are no search results is called directly in the search module so it isn't possible to edit or override it. The solution is to use the theme_box() theme hook and override the text just before it is sent to the page. Just drop the following code into your theme.php file, rename the function to fit your theme and clear your caches.

/**
 * Implements theme_box().
 */
function YOURTHEME_box($title, $content, $region = 'main') {
  if ($title == 'Your search yielded no results') {
    $title = 'Sorry, we couldn\'t find what you were looking for';
    $content = '<p>Check if your spelling is correct.</p>';
    $content .= '<p>Remove quotes around phrases to match each word individually: for example <em>"green energy"</em> will match less than <em>green energy</em>.</p>';
    $content .= '<p>Consider loosening your query with <em>OR</em>: for example <em>green energy</em> will match less than <em>green OR energy</em>.</p>';
  }
  $output = '<div style="margin:10px"><h3>'. $title .'</h3>'. $content .'</div>';
  return $output;
}

This approach is good because you can change the title and the text, not just the bit about blue smurfs. It is a quick fix that will work without having to load the Locale module just to change two words of text.

Thanks to the people on the How to Change "Search Yields no Result Text" thread for the information.

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
1 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.