• Resolved fruchtfliege

    (@fruchtfliege)


    Hello, i tried to highlight the search string in documents but it is not working. The parameter “highlight” is added by relevanssi but when inspecting the element with the search term it is not wrapped or coloured. You can see an example here: https://www.conva.de/trainings/kinder-training/?highlight=training

    I’m using ACF pro as pagebuilder with flexible layouts and indexing all custom fields. Maybe this breaks the highlighting? I already tried all settings in relevanssi but had no success.

    Should the highlighting by parameter work out of the box or do I have to add jQuery stuff to work?

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mikko Saari

    (@msaari)

    It works out of box, but only on post content. It doesn’t work on custom field based layouts, because Relevanssi has no means to add the highlights to that. The basic content is easy, just latch on to the_content filter hook.

    However, you can add the highlighting. In your template, pass the content through relevanssi_highlight_in_docs(). So, if you have echo $content;, use echo relevanssi_highlight_in_docs( $content );. That will pick up the highlighting keyword from the highlight parameter and add the highlights.

    Thread Starter fruchtfliege

    (@fruchtfliege)

    Thank you very much. Now it’s working as expected, but requires a lot of replacement in template.

    Maybe you can add an option in future, to filter all acf content (enhance output with relevanssi_highlight_in_docs.

    Kind regards

    Plugin Author Mikko Saari

    (@msaari)

    That is unfortunately not possible. ACF function get_field() doesn’t pass the field values through a filter, so filtering them is not possible.

    There are some filtering possibilities with ACF, but looks like there’s no context –?I can add the Relevanssi highlighting, but I have no way of telling when to add it and when not.

    The template level is the best approach here, even though it takes some work in the templates.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Highlighting in documents not working’ is closed to new replies.