Posted on

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.

Leave a Reply

Are you a Relevanssi Premium customer looking for support? Please use the Premium support form.

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