To highlight search

PHOTO EMBED

Sat May 14 2022 10:25:20 GMT+0000 (UTC)

Saved by @QQcoder #search

// 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">\0</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');
content_copyCOPY