wordpress highlight text excerpt

Solutions on MaxInterview for wordpress highlight text excerpt by the best coders in the world

showing results for - "wordpress highlight text excerpt"
Aisha
05 Jan 2019
1function wps_highlight_results($text){
2     if(is_search()){
3     $sr = get_query_var('s');
4     $keys = explode(" ",$sr);
5     $text = preg_replace('/('.implode('|', $keys) .')/iu', '<strong class="search-excerpt">'.$sr.'</strong>', $text);
6     }
7     return $text;
8}
9add_filter('the_excerpt', 'wps_highlight_results');
10add_filter('the_title', 'wps_highlight_results');
11