Wordpress plugins
Highlight Search Terms

Highlight Search Terms

Version : 1.4.4
Tested up to : 4.7.6
Number of download : 64243
Author : RavanH
Average rating : 5 / 5 on 20 votes 20 votes, 5 avg.rating

Screenshots

Highlight Search Terms
Highlight Search Terms
Highlight Search Terms
Highlight Search Terms

Highlights search using jQuery terms within WordPress generated search results or when referrer is a non-secure search engine. This plugin is light weight and has no options. It started as very simple fusion between How to Highlight Search Terms with jQuery – theme hack by Thaya Kareeson and Search Hilite by Ryan Boren. It has since evolved with many optimizations, HTML5 and bbPress support. Development, bug reports and contributions on https://github.com/RavanH/highlight-search-terms Features BuddyPress / bbPress compatibility: highlighting within forum searches Caching (WP Super Cache) compatibility Click through highlights: Highlights not only on WP search results page but also one click deeper inside any of the found pages Search terms wrapped in double quotes now considered as single term Support for many more search engines: Google, Bing, Yahoo, Lycos, Ask, AOL, Baidu, Youdao, Dogpile, Search.com, Goodsearch.com, Mywebsearch.com, Webcrawler.com, Info.com NOTE: to make the highlights visible in browsers that do not support HTML5 like Internet Explorer 8 or older you will have to define at least one CSS hilite styling! Read on below So what do I need to do? and Installation for more detailed instructions. You can find CSS examples in Other Notes. What does it do? This low impact plugin uses only a few action hooks to define some variables and to add the hilite jQuery extension to your page source code. The jQuery extension that runs after the page has loaded, finds all search terms on that page inside each div with class hentry (or ID content, main or wrapper…) and wraps them in <mark class="hilite term-N"> ... </mark> tags. Note that N is a number starting with 0 for the first term used in the search phrase increasing 1 for each additional term used. Any part of a search phrase wrapped in quotes is considered as a single term. What does it NOT do? There are no CSS style rules set for highlighting. You are free to use any styling you wish but to make the highlights visible in browsers that do not support HTML5 like Internet Explorer 8 or older you absolutely need to define at least one rule. Modern HTML5 browsers will use their own highlighting style by default, which usually is a yellow marker style background. So what do I need to do? In most cases, it should just work. But you can do two things to ensure backward browser and theme compatibility: 1. Define CSS rules: There are no configuration options and there is no predefined highlight styling. You are completely free to define any CSS styling rules in your themes main stylesheet (style.css) or use any Custom CSS plugin like Custom CSS to get a result that fits your theme best. You can find basic instructions and CSS examples under the Other Notes tab. 2. Check your theme: In most up to date themes (including WP’s own default theme) post and page content is shown inside a div with class hentry. This means search terms found in post and page content will be highlighted but not similar terms that accidentaly show in the page header, sidebar or footer. If your current theme does not use the hentry class (yet), this plugin will look for IDs content, main and finally wrapper but if none of those are found, it will not work for you out of the box. See the last of the FAQ’s for ways to make it work. 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. CSS Instructions 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. Basic CSS Examples .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:#000000 } Orange background with black font. For more intricate styling, see the advanced example below. Advanced CSS Example 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”! Known issues If your theme does not wrap the main content section of your pages in a div with class “hentry” or HTML5 article tags, this plugin might 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! When search engine referrer is using SSL (notice the https:// in the URL, usually when logged in as Google user) then the search terms cannot be determined. There is no way to get around that issue. Thank you, Jason for pointing out a bug for IE7+, fixed in 0.2. Please provide me with a bug report, suggestion, question on https://github.com/RavanH/highlight-search-terms/issues if you run into any problems!

Download now