I want to show on the search results page, a sentence or few words where the search term is actually located within the content in the post and display it and underline the search term.
For the title I have done similar like this:
<?php $title = get_the_title(); $keys= explode(" ",$s); $title = preg_replace('/('.implode('|', $keys) .')/iu', '<u class="search-excerpt"></u>', $title); ?>
<h3 class="test"><a href="<?php the_permalink(); ?>"><?php echo $title; ?></a></h3>
How can I show approx 15 words or so from the actual “search term” from the post content page and display it?
for example I want to make similar:
Search term = omnis
Show this = Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque
Thanks a bunch,
Kind of found one answer here:
http://atastypixel.com/blog/keeping-blog-visitors-by-showing-meaningful-search-results-in-wordpress/
If you want to use a plugin Relevanssi allows you to use a custom snippet for the returned results, for which you can set a length and choice of highlight for the searched-term.