Archived topic
Relevanssi: "Did you mean" feature
11 replies · Started by Daniel on October 3, 2018
Hello GP.Team,
I wonder if there's a way to implement this without changing the searchresults template?
https://www.relevanssi.com/knowledge-base/did-you-mean-suggestions/
Best, Daniel
Hi there,
Not 100% sure what you mean but looks like this feature is listed under the Advanced Feature of their plugin.
https://en-ca.wordpress.org/plugins/relevanssi/
Let me know this helps :)
Hi Leo,
in their documentation they say, that I have to put some custom code in my searchtemplate.
When I update GP these changes are lost, I think. My question is, if I can add this anyway in a way, that I don't lose it?
Best, Daniel
Did you make the changes in the theme's core files?
If so it will be lost during updates.
Try copy the entire file into a child theme then make changes there:
https://docs.generatepress.com/article/using-child-theme/
Let me know if this helps :)
No, I hoped there could be a snippet for the functions.php, which I can add into code snippets.
Hmm you'd have to ask them about that.
Their instruction doesn't seem to suggest so.
Just to close the topic, because I was also looking for it ...
The PHP code for the function mentioned above can either be added to the search via Elements or directly in the search.php (what I rather recommend) but then via a child theme.
maybe this will be of use to someone.
Thanks for sharing!
Hi Marcus,
could you explain me the way to do it by elements?
Best, Daniel
Hi there,
I am not sure where you want to place it on the search results, but you can try:
1. Create a new Hook Element.
2. Add your code:
<?php
if ( function_exists( 'relevanssi_didyoumean' ) ) {
relevanssi_didyoumean(
get_search_query( false ),
'<p>Did you mean: ',
'</p>',
5
);
}
?>
3. Select the generate_before_main_content hook
4. Check execute PHP
5. Set the Display Rules to: Search Results.
Thank you David. That worked very well!
Glad to hear that!