How To Change No Search Results Text In Drupal 6

2nd February 2012

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.

  1. /**
  2.  * Implements theme_box().
  3.  */
  4. function YOURTHEME_box($title, $content, $region = 'main') {
  5. if ($title == 'Your search yielded no results') {
  6. $title = 'Sorry, we couldn\'t find what you were looking for';
  7. $content = 'Check if your spelling is correct.';
  8. $content .= 'Remove quotes around phrases to match each word individually: for example "green energy" will match less than green energy.';
  9. $content .= 'Consider loosening your query with OR: for example green energy will match less than green OR energy.';
  10. }
  11. $output = ''. $title .''. $content .'';
  12. return $output;
  13. }

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.