Highlight Search Results
-
I found this function on the net. I have placed this in my custom functions file separate from functions.php.
function highlight_search_term($text){ if(is_search()){ $keys = implode('|', explode(' ', get_search_query())); $text = preg_replace('/(' . $keys .')/iu', '<span class="search-term">\1</span>', $text); } return $text; } add_filter('the_excerpt', 'highlight_search_term'); add_filter('the_title', 'highlight_search_term');
It works fine except it alters the read more link. Hovering over this link shows:
http://www.mysite.com/%3span%20classs=
When it is removed the link is unaffected. What is wrong with it? I have used the following CSS with it:
.search-excerpt { background: yellow; }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Highlight Search Results’ is closed to new replies.