Posted by KaiseRCrazY on 21st July 2009

How to Highlight Searched Text In Results

You can highlight searched text in search results. WordPress search system is powerfull but some things not acceptable for me :) i searched on internet and found this code for theme developers. You can add this special code to your theme. You need to change serach.php and your style.css.First open your search.php with your favourite php editor;

Find the_title() function and replace with

echo $title;

After than add this code to before modified line

<?php
 $title  = get_the_title();
 $keys= explode(" ",$s);
 $title  = preg_replace('/('.implode('|', $keys) .')/iu',
 '<strong class="search-excerpt">\0</strong>',  $title);
?>

And Last Step :)

Add this line to your style.css

strong.search-excerpt { background: yellow; }

You can change ‘yellow’ with a color code or color name.

That’s All! Have a nice day!

  • del.icio.us
  • Digg
  • Facebook
  • FriendFeed
  • Reddit
  • StumbleUpon
  • Technorati
  • PDF
  • Print

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

No comments yet!

Post your comments