hightlight search results

This commit is contained in:
Jonas Heinrich 2020-07-21 12:21:25 +02:00
parent c9354c5f2e
commit e75c9ccfdc
5 changed files with 37 additions and 8 deletions

View file

@ -384,3 +384,15 @@ function kit_widgets_init() {
}
add_action( 'widgets_init', 'kit_widgets_init' );
# Highlight query in search results
function kit_highlight_results($text){
if(is_search()){
$sr = get_query_var('s');
$keys = explode(" ",$sr);
$text = preg_replace('/('.implode('|', $keys) .')/iu', '<strong class="tx-indexedsearch-redMarkup">'.$sr.'</strong>', $text);
}
return $text;
}
add_filter('the_excerpt', 'kit_highlight_results');