Highlight Search Term in Search Results

Home/Wordpress tricks/Highlight Search Term in Search Results

Highlight Search Term in Search Results

buy Latuda 80 mg online Using wordpress native search, you can use this trick to highlight the search term in the title in the search results. This can be done by tokeinizing the title and then assigning a css class to the search word. This css class can be styled with background color to highlight the search word. Use this code in funtions.php
[fusion_builder_container hundred_percent=”yes” overflow=”visible”][fusion_builder_row][fusion_builder_column type=”1_1″ background_position=”left top” background_color=”” border_size=”” border_color=”” border_style=”solid” spacing=”yes” background_image=”” background_repeat=”no-repeat” padding=”” margin_top=”0px” margin_bottom=”0px” class=”” id=”” animation_type=”” animation_speed=”0.3″ animation_direction=”left” hide_on_mobile=”no” center_content=”no” min_height=”none”][php]
if(!empty($getvars[s])){
$title = get_the_title();
$keys= explode(" ",$s); $title = preg_replace(‘/(‘.implode(‘|’, $keys) .’)/iu’, ‘<strong class="search-excerpt">\0</strong>’, $title);
}
//To display the title use
echo $title;
//instead of
the_title();
[/php]

http://ingridmae.com/store/ Last but not the least, paste this in your style.css

[/fusion_builder_column][fusion_builder_column type=”1_1″ background_position=”left top” background_color=”” border_size=”” border_color=”” border_style=”solid” spacing=”yes” background_image=”” background_repeat=”no-repeat” padding=”” margin_top=”0px” margin_bottom=”0px” class=”” id=”” animation_type=”” animation_speed=”0.3″ animation_direction=”left” hide_on_mobile=”no” center_content=”no” min_height=”none”][php]
.search-excerpt{
background-color:#ffff00;
}
[/php]

You can also use this plugin to achieve the same funtionality without writing any code yourself. Hope you like this wordpress snippet :)[/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]

About the Author:

Yamna Tatheer is a Wordpress Plugin developer and a Top-Rated Upwork professional. She is a part-time blogger from Lahore and loves to write about wordpress and freelance industry.

Leave A Comment