<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WpFunc &#187; highlight searched text</title>
	<atom:link href="http://wpfunc.com/tag/highlight-searched-text/feed" rel="self" type="application/rss+xml" />
	<link>http://wpfunc.com</link>
	<description>Awesome, Quick, Simple WordPress Functions!</description>
	<lastBuildDate>Sun, 06 May 2012 02:21:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Highlight the Searched Text!</title>
		<link>http://wpfunc.com/wordpress/highlight-the-searched-text.html</link>
		<comments>http://wpfunc.com/wordpress/highlight-the-searched-text.html#comments</comments>
		<pubDate>Tue, 22 Sep 2009 19:59:47 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[functions.php]]></category>
		<category><![CDATA[header.php]]></category>
		<category><![CDATA[highlight]]></category>
		<category><![CDATA[highlight searched text]]></category>
		<category><![CDATA[search term]]></category>
		<category><![CDATA[search terms]]></category>

		<guid isPermaLink="false">http://www.wpfunc.com/?p=202</guid>
		<description><![CDATA[Some themes have a highlighted search page, some themes don&#8217;t have this page too. But i will give some code to you. With this code you can highlight the searched text on your theme. This function may help your users when they search any important things. Lets Begin.. Here is the code; First make a [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Some themes have a highlighted search page, some themes don&#8217;t have this page too. But i will give some code to you. With this code you can highlight the searched text on your theme. This function may help your users when they search any important things. Lets Begin..<span id="more-202"></span></p>
<p style="text-align: justify;"><span class="attention">We will change our theme&#8217;s <strong>function.php</strong> and <strong>header.php</strong>. If you don&#8217;t know about WordPress coding or PHP please don&#8217;t touch this files. If you wanna help send me e-mail about this function.</span></p>
<h3 style="text-align: justify;">Here is the code;</h3>
<p style="text-align: justify;">First make a backup functions.php and header.php (These files under the your themes path [<strong>wp-content/theme/your-theme</strong>]). After backup, you can change this files and you can send them to your server.</p>
<p style="text-align: justify;">Insert this code into <strong>theme&#8217;s Functions.php</strong>:</p>
<pre class="brush: plain; title: ; notranslate">function hls_set_query() {
  $query  = attribute_escape(get_search_query());

  if(strlen($query) &gt; 0){
    echo '
      &lt;script type=&quot;text/javascript&quot;&gt;
        var hls_query  = &quot;'.$query.'&quot;;
      &lt;/script&gt;
    ';
  }
}

function hls_init_jquery() {
  wp_enqueue_script('jquery');
}

add_action('init', 'hls_init_jquery');
add_action('wp_print_scripts', 'hls_set_query');
</pre>
<p style="text-align: justify;">And after that, Open your <strong>theme&#8217;s header.php</strong> and paste this code before <strong>&lt;/head&gt;</strong> tag.</p>
<pre class="brush: plain; title: ; notranslate">&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;
    .hls { background: #D3E18A; }
  &lt;/style&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
  jQuery.fn.extend({
    highlight: function(search, insensitive, hls_class){
      var regex = new RegExp(&quot;(&lt;[^&gt;]*&gt;)|(\\b&quot;+ search.replace(/([-.*+?^${}()|[\]\/\\])/g,&quot;\\$1&quot;) +&quot;)&quot;, insensitive ? &quot;ig&quot; : &quot;g&quot;);
      return this.html(this.html().replace(regex, function(a, b, c){
        return (a.charAt(0) == &quot;&lt;&quot;) ? a : &quot;&lt;strong class=\&quot;&quot;+ hls_class +&quot;\&quot;&gt;&quot; + c + &quot;&lt;/strong&gt;&quot;;
      }));
    }
  });
  jQuery(document).ready(function($){
    if(typeof(hls_query) != 'undefined'){
      $(&quot;#post-area&quot;).highlight(hls_query, 1, &quot;hls&quot;);
    }
  });
  &lt;/script&gt;
</pre>
<p style="text-align: justify;">After that you can send files to your server. When you search you can see searched texts are highlighted!</p>
]]></content:encoded>
			<wfw:commentRss>http://wpfunc.com/wordpress/highlight-the-searched-text.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

