At some instant we need to Highlight searched text in our WordPress Search Results.There are lot of plugin available which is able to handle it. Today we will see how to Highlight Searched text in Search Results in WordPress using code, or modifying search.php. After adding this code in your search.php you don’t need to install any plugin.
I am admitting that I’m not a big fan of the WordPress built-in search engine. One of its weakest features is the fact that searched text aren’t highlighted in the results, so the visitor is unable to see the searched text in the context of your article. This code has been created by Joost de Valk who blogs at www.yoast.com.
How To WordPress Highlight Searched Text in Search Results
You need to follow some basic steps given below:
1 ) Open your search.php file and find the the_title() function. Replace it with the following:
2) Now, just before the modified line, add this code:
$title = get_the_title();
$keys= explode(" ",$s);
$title = preg_replace('/('.implode('|', $keys) .')/iu',