\n showing in search results

Hi Themeco,
I am using Relevanssi to control search results on my site which also uses the Pro theme.
What I have found is that pages built in cornerstone are showing \n\n in the search results.

I found this post with the same issue: Strange Line Break effect at Search Result Page where the issue is explained in detail.

I need to control the search results as the standard wp search is not quite right in terms of relevancy etc.

Can you help me fix this issue or suggest another plugin which is compatible with Pro and wont show these line break characters.

I look forward to hearing from you.

Tamsin

The \n\n code seems to show where there was a heading or button. I have checked for any pasted styles or other manually added code but it is not in the content.

Hey @pyntolimited,

Thanks for writing in! I would recommend that you use Manual Excerpts for posts and pages that were built in Cornerstone. This way when the excerpts are displayed in the Search Results, the custom manual excerpts will be displayed.

Regretfully we do not have any recommended alternative plugin for Relevanssi.

Best Regards.

Thank you for getting back to me. Manual excerpts does not solve this problem. I have manual excerpts working and there is one set for this page.

The excerpt chosen is from the content and related to the search keyword. This functionality is part of the Relevanssi search.

Did you see the ticket I referenced? Was there a solution found there? The user said the same issue was happening with Rank Math too.

I hope you are able to help as I can’t have this code showing in my search results and have put quite a bit of work into setting up this search facility. I would be happy to use another plugin to control the search instead of Relevanssi but it seems to be a very good and widely used option.

I look forward to hearing from you.

Tamsin

Hello Tamsin,

There was no resolution in the reference thread. The plugin renders the content and is responsible for adding \n in the search results. You may need to contact the creators of the plugin and see if the provided PHP code works with the theme builder’s output and not adding any \n character.

Be advised that this 3rd party is not fully integrated and/or connected with the creators of the plugin.

Thank you for your understanding.

Thank you, I contacted Relevanssi and they gave me some code to add to the functions file which solved the problem and removed the characters:

"There’s something in your post content that causes the line feed encoding go wonky when Relevanssi generates the excerpts. These line feeds should just disappear. I can’t see any particular reason for this on the Stannah Stairlifts page source code.

Relevanssi has good filter hooks you can probably use to fix this. Try this:

add_filter( 'relevanssi_excerpt', function( $excerpt ) {  return str_replace( '\n', ' ', $excerpt );} );

Add this to your theme functions.php or in a code snippet."

Here is the thread: https://wordpress.org/support/topic/nn-characters-showing-in-search-results/
Hopefully this will help someone else too.

Hey @pyntolimited,

Thanks for sharing the fixes to your issue, this will help another customer who faced the same integration and we’re glad that it is now working properly on your end.

Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.