• Resolved semoliner

    (@semoliner)


    Hi, ‘Create custom search result snippets’ is enabled but since updating to 4.12.0 I’ve noticed that after navigating to pages via the search results, the query terms are no longer highlighted in the documents. This is because the URL is no longer appended with the ?highlight=

    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)

    This behaviour was changed in 4.12.0. Previously Relevanssi would add the highlight parameter to all links when is_search() is true, which would mean all links on the search results page would get the highlight, even things like menus and widgets. In 4.12.0 Relevanssi only adds highlight if the post has the relevance_score attribute from Relevanssi added, so it should only be added to the posts that come from Relevanssi.

    What does your search results template look like?

    Thread Starter semoliner

    (@semoliner)

    I’m using the Astra theme, and this is the default search.psp – in a previous post here you commented that it was quite non-standard compared to other themes, so anyway, this is the default without any changes:

    <?php
    /**
    * The template for displaying search results pages.
    *
    * @link https://developer.www.ads-software.com/themes/basics/template-hierarchy/#search-result
    *
    * @package Astra
    * @since 1.0.0
    */

    if ( ! defined( ‘ABSPATH’ ) ) {
    exit; // Exit if accessed directly.
    }

    get_header(); ?>

    <?php if ( astra_page_layout() == ‘left-sidebar’ ) : ?>

    <?php get_sidebar(); ?>

    <?php endif ?>

    <div id=”primary” <?php astra_primary_class(); ?>>

    <?php astra_primary_content_top(); ?>

    <?php astra_archive_header(); ?>

    <?php astra_content_loop(); ?>

    <?php astra_pagination(); ?>

    <?php astra_primary_content_bottom(); ?>

    </div><!– #primary –>

    <?php get_footer(); ?>`

    
    
    Now, additionally, here are the changes made to my functions.php by both you and by Astra support - so you may find some of this familiar - and if you need me to post the entire functions.php (standard Astra) just let me know:
    
    <code></code>/**
     * Added by Astra support so that page Titles are displayed on the Search Results page instead of just More >>
     */
    function new_excerpt_more($more) {
    	return '';
    	}
    
    function the_excerpt_more_link( $excerpt ){
    	$post = get_post();
    	$excerpt .= '<p class="read-more"><a href="'. get_permalink($post->ID) . '">'. get_the_title() . ' ?</a></p>';
    	return $excerpt;
    }
    
    function read_more_callback(){
    	if(is_search()){
    		add_filter( 'the_excerpt', 'the_excerpt_more_link', 21 );
    		add_filter('excerpt_more', 'new_excerpt_more', 21 );
    	}
    }
    
    add_action('wp' , 'read_more_callback');
    
    /**
     * Added by Mikko Saari otherwise Relevanssi on-page highlighting messes up the quotes in the data parameters related to Elementor image animations
     */
    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( '"', '&quot;', $match );
            }
            $content = str_replace( $source, $replace, $content );
        }
        return $content;
    } );

    `

    Thread Starter semoliner

    (@semoliner)

    Sorry that paste got really messed up so you have got what I wanted you to see in functions.php, let’s try again for search.php…

    <?php
    /**
    * The template for displaying search results pages.
    *
    * @link https://developer.www.ads-software.com/themes/basics/template-hierarchy/#search-result
    *
    * @package Astra
    * @since 1.0.0
    */

    if ( ! defined( ‘ABSPATH’ ) ) {
    exit; // Exit if accessed directly.
    }

    get_header(); ?>

    <?php if ( astra_page_layout() == ‘left-sidebar’ ) : ?>

    <?php get_sidebar(); ?>

    <?php endif ?>

    <div id=”primary” <?php astra_primary_class(); ?>>

    <?php astra_primary_content_top(); ?>

    <?php astra_archive_header(); ?>

    <?php astra_content_loop(); ?>

    <?php astra_pagination(); ?>

    <?php astra_primary_content_bottom(); ?>

    </div><!– #primary –>

    <?php get_footer(); ?>

    Plugin Author Mikko Saari

    (@msaari)

    I think this should work:

    function the_excerpt_more_link( $excerpt ){
    	$post = get_post();
    	$function = function_exists( 'relevanssi_get_permalink' ) ? 'relevanssi_get_permalink' : 'get_permalink';
    	$excerpt .= '<p class="read-more"><a href="'. call_user_func( $function, $post->ID ) . '">'. get_the_title() . ' ?</a></p>';
    	return $excerpt;
    }
    • This reply was modified 3 years, 9 months ago by Mikko Saari.
    Thread Starter semoliner

    (@semoliner)

    functions.php doesn’t seem to accept that?

    Plugin Author Mikko Saari

    (@msaari)

    There was a colon where a question mark should’ve been. I’ve fixed it now.

    Thread Starter semoliner

    (@semoliner)

    Perfect! Thanks so much Mikko.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Query terms not highlighted since update’ is closed to new replies.