Advertisement
zinannadeem

Search Result String Highlighting in WP

Jan 28th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.43 KB | None | 0 0
  1. /**
  2.  * Register Search Result String Highlighting.
  3.  *
  4.  */
  5. function wps_highlight_results($text){
  6.      if(is_search()){
  7.      $sr = get_query_var('s');
  8.      $keys = explode(" ",$sr);
  9.      $text = preg_replace('/('.implode('|', $keys) .')/iu', '<strong class="search-excerpt">'.$sr.'</strong>', $text);
  10.      }
  11.      return $text;
  12. }
  13. add_filter('the_excerpt', 'wps_highlight_results');
  14. add_filter('the_title', 'wps_highlight_results');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement