Lightweight search terms highlighter using jQuery. Wraps search terms with class="hilite" when referer is a search engine or within wp searc
Many blogs are already top-heavy with all kinds of resource hungry plugins that require a lot of options to be set and subsequently more database queries. The Highlight Search Terms plugin for WordPress is constructed to be as low impact / low resource demanding as possible, keeping server response and page load times low. This is done by going without any back-end options page, no filtering of post content and no extra database entries. Just two action hooks are used: wp_footer and wp_head. The rest is done by jQuery javascript extention and your own CSS.
To get you started with your own CSS styling that fits your theme, see the following examples.
Go in your WP admin section to Themes > Edit and find your Stylesheet. Scroll all the way to the bottom and add one of the examples (or your modification of it) on a fresh new line.
.hilite { background-color:#D3E18A }
For a moss green background highlighting.
.hilite { background-color:yellow }
Yellow background highlighting.
.hilite { background-color:#9CD4FF; font-weight:bold }
A light blue background with bold font.
.hilite { background-color:#FFCA61; color:#0000 }
Orange background with black font.
For more intricate styling, see the advanced example below.
If you want to give different terms used in a search phrase a different styling, use the class "term-N" where N is a number starting with 0, increasing 1 with each additional search term, to define your CSS rules. The below example will make every instance of any term used in the query show up in bold text and a yellow background except for any instance of a second, third and fourth term which will have respectively a light green, light blue and orange background.
.hilite { background-color:yellow; font-weight:bold } /* default */
.term-1 { background-color:#D3E18A } /* second search term only */
.term-2 { background-color:#9CD4FF } /* third search term only */
.term-3 { background-color:#FFCA61 } /* fourth search term only */
Keep in mind that for the first search term the additional class "term-0" is used, not "term-1"!
If your theme does not wrap the main content section of your pages in a div with class "hentry", this plugin will not work for you out of the box. However, you can make it work. See the last of the FAQ's for an explanation.
Josh pointed out a conflict with the ShareThis button. I have no clue why this happens but since version 0.5 jQuery is used in so called NoConflict mode. Please let me know if the problem still exists. Thanks!
Thank you, Jason for pointing out a bug for IE7+, fixed in 0.2.
Please provide me with a bugreport, suggestion or question if you run into any problems!
Requires: 2.3 or higher
Compatible up to: 3.1.4
Last Updated: 2011-1-3
Downloads: 9,627




