Created
November 24, 2014 09:46
-
-
Save webgurus/00180fd576eb37b57be4 to your computer and use it in GitHub Desktop.
Highlight WP Search results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// HIGHLIGHT SEARCH RESULTS | |
function wps_highlight_results($text){ | |
if(is_search()){ | |
$sr = get_query_var('s'); | |
$keys = explode(" ",$sr); | |
$text = preg_replace('/('.implode('|', $keys) .')/iu', '<span class="label label-default">'.$sr.'</span>', $text); | |
} | |
return $text; | |
} | |
add_filter('the_excerpt', 'wps_highlight_results'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment