Quick Tip: Add excerpts to search results page

If you’ve tried searching for a keyword on a WP site, you may have noticed that the search results don’t always include an excerpt of matching page(s). While you’re at it, have you tried the search function on your site? The missing excerpt is not WordPress’s fault, in reality the theme designer neglected or chose not to include that feature in the theme.

Here’s how to quickly add an excerpt to your search results page by hacking your theme. Important: make sure you have a copy of your original theme and/or backup the existing search.php page ready to restore in case you get in trouble. We’re not responsible if you muck up your site.

In WordPress admin, select Appearance -> Editor -> Search.php (screenshot below) Add the following tag after the end of the headline tag, usually </h2>:

<?php the_excerpt(); ?>

And hit “Save” and go try a search on your site!

the_excerpt_wordpress_code.jpg

Another tip, now that you’ve improved it with excerpts,  why not improve it further by trying Relevanssi plugin? Relevannsi will help bump up the quality of matching results. You’ll still need to  do a bit of work tagging your posts or pages but it’s worth it.