Skip to main contentSkip to footer

Disable in-page highlights on a specific page

Sometimes there’s a need to disable the in-page highlighting on specific pages. Perhaps the feature works fine on most pages, but some pages have content that is broken by the highlighting.

In theory, disabling the feature is very simple: remove the relevanssi_highlight_in_docs filter function from the the_content hook for that page. In practise, getting it to work requires good timing so that you remove the filter hook after Relevanssi sets it but before it is run.

Add this function to your site to fix this problem:

add_action( 'parse_query', function() {
    global $wp_query;
    $excluded_page_ids = array( 1, 2, 3 );
    if ( in_array( $wp_query->queried_object_id, $excluded_page_ids, true ) ) {
        remove_filter( 'the_content', 'relevanssi_highlight_in_docs', 11 );
  }
}, 2 );

List the page ID numbers for the excluded pages in the $excluded_page_ids array.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Italian plurals
A Relevanssi user asked about Italian plurals on the Relevanssi support forums. The best answer is to use the Relevanssi…
Taxonomy archive search
This is a Premium feature and only applies when you index taxonomy terms. This does not apply in free Relevanssi.…
Ultimate FAQs
Ultimate FAQs is a FAQ plugin that can create FAQs. It has a search, and enabling Relevanssi may break that…

Related Posts:

Currently there are no related posts available.

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed