Search
 
SCRIPT & CODE EXAMPLE
 

PHP

wordpress highlight text excerpt

function wps_highlight_results($text){
     if(is_search()){
     $sr = get_query_var('s');
     $keys = explode(" ",$sr);
     $text = preg_replace('/('.implode('|', $keys) .')/iu', '<strong class="search-excerpt">'.$sr.'</strong>', $text);
     }
     return $text;
}
add_filter('the_excerpt', 'wps_highlight_results');
add_filter('the_title', 'wps_highlight_results');
Comment

PREVIOUS NEXT
Code Example
Php :: check multiple roles with Blade directive @can? 
Php :: no routes.php in http folder 
Php :: php huruf besar di awal 
Php :: laravel cookie (flash meesage for time) 
Php :: database connection in pdo php 
Php :: spatie laravel pdf image 
Php :: php capture include 
Php :: wc php product_cat thumbnail 
Php :: uft8 json php 
Php :: laravel queue work schedule cpanel 
Php :: public variable in php 
Php :: laravel eloquent with query parameter 
Php :: How do I display logged-in username IF logged-in? site:wordpress.stackexchange.com 
Php :: get 2 hrs before data in php 
Php :: php artisan preset bootstrap 
Php :: static variable php 
Php :: symfony append to file 
Php :: php get woocommerce attribute from database 
Php :: bd sms gateway, laravel sms gateway, sms sending library, bd sms, sms gateway 
Php :: custom blade directive 
Php :: laravel repository update multiple row 
Php :: Undefined property: stdClass::$ 
Php :: check url parameter if not redirect wordpress 
Php :: isset in php 
Php :: Best documentation tools for php 
Php :: how to remove last element from php array 
Php :: php unix socket client 
Php :: overloading and overriding in php 
Php :: remove field from object php 
Php :: wordpress shortcode api 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =