• Hey Mikko,
    I would like to highlight the search results on the document leading from the search results page. I have checked the option “Highlight query terms in documents” in the “highlights and excerpts” tab, but it doesn’t work. What am I missing out?
    Many thanks !
    Ruth

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

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

    (@msaari)

    There should be a highlight parameter in the links to the pages, like this: /17-היחידה-הממשלתית-לחופש-המידע/?highlight=חופש+המידע. For some reason, it’s not there. How is your theme printing out the links to the pages on the search results template? If you enable the option, Relevanssi should automatically add the highlight parameter, if you’re using the_permalink() to print out the link.

    Looks like adding the highlights does break some elements on your site. You probably need the second code snippet from this page.

    Thread Starter ruth22

    (@ruth22)

    Thank you Mikko,
    I’ve added the code in both snippets actually.
    If you open the link I’ve attached you could see that the first result doesn’t come with highlights but the second result does. Something is not working as it should.
    I am using a simple Search Results Elementor template with the Post Archive widget.
    Many thanks,
    Ruth

    Plugin Author Mikko Saari

    (@msaari)

    I see no highlights at all, not even in the second result, the highlight parameter is missing. It is possible Elementor is printing the links in a way where Relevanssi can’t insert the highlight parameter to the links automatically.

    Thread Starter ruth22

    (@ruth22)

    Hi Mikko,
    Managed to fix this, thanks! **but** there is a strange code appearing on top of the results page -here is the link: http://www.foiguide.org.il/15-שיקולים-נוספים-של-הרשות/?highlight=חופש%20מידע

    How do I remove it?
    Many thanks,
    Ruth

    Plugin Author Mikko Saari

    (@msaari)

    I saw that, and that’s why I recommended you should use the second code snippet from the Relevanssi Elementor page. If you have it and it’s not helping, then I don’t know the solution. It’s some Elementor element that is breaking. Do you have any idea what in Elementor that could be?

    Thread Starter ruth22

    (@ruth22)

    It could be the secondary navigation menu. When I delete it, this doesn’t happen. But this is a crucial part of the page…

    Plugin Author Mikko Saari

    (@msaari)

    As far as I can tell, this snippet should fix the problem:

    add_filter( 'relevanssi_clean_excerpt', function( $content ) {
        if ( preg_match_all( '/data-settings="(.*?)"[ >]/', $content, $matches ) ) {
            $source  = array();
            $replace = array();
            foreach ( $matches[1] as $match ) {
                $source[]  = $match;
                $replace[] = str_replace( '"', '"', $match );
            }
            $content = str_replace( $source, $replace, $content );
        }
        return $content;
    } );

    That’s the general problem, at least: Relevanssi highlighting is breaking the settings data. But I don’t know, I’d need to see how exactly it is breaking, perhaps this case needs some adjustments.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Highlights in documents’ is closed to new replies.