How to Highlight Search Results in WordPress

How to Highlight Search Results in WordPress

Today i am showing How to Highlight Search Results in WordPress Website.

Paste this code on your function.php file

// highlight search result 
function skyboot_search_result_highlight($text){
	if( is_search() ){
		$pattarn = '/( '.join( '|', explode(' ', get_search_query(  )) ).' )/i';
		$text = preg_replace($pattarn, '<span class="search-excerpt">
// highlight search result 
function skyboot_search_result_highlight($text){
	if( is_search() ){
		$pattarn = '/( '.join( '|', explode(' ', get_search_query(  )) ).' )/i';
		$text = preg_replace($pattarn, '<span class="search-excerpt">\0</span>', $text);

	}
	return $text;
}
add_filter( 'the_content', 'skyboot_search_result_highlight' );
add_filter( 'the_excerpt', 'skyboot_search_result_highlight' );
add_filter( 'the_titLE', 'skyboot_search_result_highlight' );
</span>', $text); } return $text; } add_filter( 'the_content', 'skyboot_search_result_highlight' ); add_filter( 'the_excerpt', 'skyboot_search_result_highlight' ); add_filter( 'the_titLE', 'skyboot_search_result_highlight' );

Paste this code on your css file

span.search-excerpt { 
background-color:yellow;
color:red;
}

Published by skyboot

Skybootstrap is a web Design and Development service provider. Our Service: WordPress Theme Development | PSD to WordPress | Dropshipping Store Create | Shopify Store Create | Wp Error Fix | Contact Form | Landing Page Create | Bootstrap Landing Page .

Leave a Reply

Your email address will not be published. Required fields are marked *