Note: You are viewing the documentation for Version 4View Version 3 Docs

\SearchWP\Highlighter

Table of Contents

\SearchWP\Highlighter can highlight strings within strings.

Basic Usage

All usage of \SearchWP\Highlighter requires two parameters, a $haystack and a $needle. A $needle within a $haystack will be wrapped in a <mark class="searchwp-highlight"/> element.

<?php
$highlighter = new \SearchWP\Highlighter();
$haystack = 'The ACME Brewmaster makes the best coffee you can find!';
$needle = 'coffee';
// Output: The ACME Brewmaster makes the best <mark class="searchwp-highlight">coffee</mark> you can find!
echo $highlighter->apply( $haystack, $needle );
view raw page-template.php hosted with ❤ by GitHub

Methods

apply( string $haystack, string $needle)
Highlight the $needle in the $haystack

Hooks

There are a number of hooks available to further modify the behavior of \SearchWP\Highlighter:

Fix keyword search on your site. No coding required!

Now you can utilize all of the content that's gone unrecognized by native WordPress keyword search instantly with SearchWP

Get SearchWP