Using wordpress native search, you can use this trick to highlight the search term in the title in the search results. This can be done by tokeinizing the title and then assigning a css class to the search word. This css class can be styled with background color to highlight the search word. Use this code in funtions.php

			$title = get_the_title();
			$keys= explode(" ",$s); $title = preg_replace('/('.implode('|', $keys) .')/iu', '<strong class="search-excerpt">\0</strong>', $title);
//To display the title use
echo $title;
//instead of

Last but not the least, paste this in your style.css


You can also use this plugin to achieve the same funtionality without writing any code yourself. Hope you like this wordpress snippet 🙂

Yumna Tatheer

I am a Computer Science graduate and a part time blogger from Lahore, Pakistan. I am a PHP programmer and a wordpress expert.

More Posts

Follow Me: