Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
Last active April 22, 2020 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgibbs189/ab9ee109b0230198319326c9c6d901db to your computer and use it in GitHub Desktop.
Save mgibbs189/ab9ee109b0230198319326c9c6d901db to your computer and use it in GitHub Desktop.
FacetWP - support SearchWP term highlight
<?php
/**
* Modify the output HTML and highlighting all search terms
*/
add_filter( 'facetwp_render_output', function( $output, $params ) {
$keywords = '';
if ( isset( FWP()->facet->facets['keywords'] ) ) {
$keywords = FWP()->facet->facets['keywords']['selected_values'];
$keywords = is_array( $keywords ) ? implode( ' ', $keywords ) : $keywords;
}
if ( ! empty( $keywords ) && class_exists( 'SearchWPHighlighter' ) ) {
$highlighter = new SearchWPHighlighter();
$output['template'] = $highlighter->apply_highlight( $output['template'], $keywords );
}
return $output;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment