Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

search highlighting

// Search Highlighting
function buson_highlight_search_results($text)
{
   if (is_search()) {
      $pattern = '/('. join('|', explode(' ', get_search_query())).')/i';
      $text = preg_replace($pattern, '<span class="search-highlight"></span>', $text);
   }
   return $text;
}
add_filter('the_content', 'buson_highlight_search_results');
add_filter('the_excerpt', 'buson_highlight_search_results');
add_filter('the_title', 'buson_highlight_search_results');
Source by learnwith.hasinhayder.com #
 
PREVIOUS NEXT
Tagged: #search #highlighting
ADD COMMENT
Topic
Name
8+7 =