• Posted: 2010-09-10
  • Author: Filip Stefansson
  • Tags:

Highlight search-result

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
<?php
// Replace the_exerpt() with:
$excerpt = get_the_excerpt();
$keys = explode(" ",$s);
$excerpt = preg_replace('/('.implode('|', $keys) .')/iu', '<strong class="search-excerpt">\0</strong>', $excerpt);
echo $excerpt;

Instructions:

If you want to make it easier for your users that are using the serach-function, you can highlight the word they searched on. All changes goes in search.php.

Edit the class .search-excerpt as you want your highlight to look!


Related links:
http://www.wprecipes.com/how-to-enlight-searched-text-in-search-results
Share this snippet

If you like this snippet, share it with friends!