diff --git a/kit/functions.php b/kit/functions.php index 5893f05..592df0f 100644 --- a/kit/functions.php +++ b/kit/functions.php @@ -431,32 +431,14 @@ add_action( 'widgets_init', 'kit_widgets_init' ); # Highlight query in search results -function highlight_search_term_placeholders() { - static $iter = 0; - $ret = "|##{$iter}##|"; - $iter++; - return $ret; -} -function highlight_search_term_cb() { - static $iter = 0; - $ret = "##{$iter}##"; - $iter++; - return $ret; -} -function highlight_search_term($text){ - if(is_search() && !is_admin()){ - $keys = implode('|', explode(' ', get_search_query())); - $pattern = '/<[^>].*?>/i'; - preg_match_all($pattern,$text,$matches); - $placeholders = array(); - foreach ($matches[0] as $v) { - $placeholders[] = highlight_search_term_placeholders(); +function highlight_results($text) { + if (is_search() && !is_admin()) { + $sr = get_query_var('s'); + $keys = explode(' ', $sr); + $keys = array_filter($keys); + $text = preg_replace('/('.implode('|', $keys) .')/iu', '\0', $text); } - $text = preg_replace_callback($pattern,'highlight_search_term_cb',$text); - $pattern2 = '/(' . $keys .')/iu'; - $text = preg_replace($pattern2, ' \1 ', $text); - $text = preg_replace($placeholders,$matches[0],$text); - } - return $text; + return $text; } -add_filter('the_excerpt', 'highlight_search_term'); + +add_filter('the_excerpt', 'highlight_results');