WordPress Fixes: Showing content – not excerpt in searches.

Came across this one and it took a little tracking down to fix – so in case someone else has this issue – here’s how I fixed it 😉

The Problem…

Search result pages in WordPress are showing a generated snippet from the post content, not the excerpt.   After confirming that the post does indeed have a custom excerpt specified for it, here’s what I did next…

the_excerpt()

First thing to do is the check is that you are using the_excerpt() in your template.  Look in your /wp-content/themes/[yourtheme] folder for search.php or if that’s not there – index.php.

In that file find the wordpress loop – it’ll start like this…
while (have_posts()) : the_post();

Make sure it has the_excerpt(); not the_content();, it could be like this

<?php if (is_archive() || is_search()) { ?>
    <?php the_excerpt(); ?>
<?php } else { ?>
    <?php the_content(); ?>
<?php } ?>

If you can see the_excerpt() – chances are you have the right template.

Plugins…

Once you’ve confirmed the templates is correct and the post has an excerpt, then you need start disabling plugins.
If possible turn them all off – then enable one at a time till you find the offender.
If it still happens with all plugins disabled, then its definitely your theme that’s to blame.

For me..

In my case the problem turned out to be (obviously with hindsight) Relevanssi. Relevanssi has an option to reformat your search result content to show the relevant result. This most likely results in a part of the content being shown – not the excerpt you specified. Its just a tickbox away to fix (Create custom search result snippets) 😉

Hope this helps save someone some time debugging!

Author: Sable

Site owner. Just me - nothing more, nothing less.

Leave a Reply