Search
 
SCRIPT & CODE EXAMPLE
 

PHP

search highlighting

// Search Highlighting
function buson_highlight_search_results($text)
{
   if (is_search()) {
      $pattern = '/('. join('|', explode(' ', get_search_query())).')/i';
      $text = preg_replace($pattern, '<span class="search-highlight"></span>', $text);
   }
   return $text;
}
add_filter('the_content', 'buson_highlight_search_results');
add_filter('the_excerpt', 'buson_highlight_search_results');
add_filter('the_title', 'buson_highlight_search_results');
Comment

PREVIOUS NEXT
Code Example
Php :: symfony translation variable in twig 
Php :: cake php 2.x group 
Php :: woocommerce affiliate product link image to external link 
Php :: how to check if a url has a certain word in laravel 
Php :: Comment rediriger la page “Panier” et sauter la page Commande 
Php :: how we generate a single column migration in laravel 
Php :: How can I display the data stored by summernote on laravel? 
Php :: laravel cors error localhost 
Php :: Sorting Products by Custom Meta Fields 
Php :: PHP strpos — Find the position of the first occurrence of a substring in a string 
Php :: magento 2 isSetFlag() 
Php :: Argument 1 passed to IlluminateDatabaseGrammar::parameterize() 
Php :: php pdo bindvalue array 
Php :: string length php online 
Php :: IlluminateDatabaseQueryException SQLSTATE[HY000]: General error: 3780 Referencing column 
Php :: simple-phpunit --version handling the phpunit-setup event returned with error code 127 on ubuntu 
Php :: function to fetch user details 
Php :: apache/2.4.53 (win64) openssl/1.1.1n php/8.1.5 server at localhost port 80 
Php :: @parent laravel 
Php :: wp clean db terms 
Php :: advanced custom fields echo string replace 
Php :: PHP SimpleXML - Get Node/Attribute Values 
Php :: Laravel Query: orderBy not working with groupBy (with a joined table) 
Php :: laravel load relationship including empty values 
Php :: laravel eloquent get current sequence value 
Php :: remove nul value aray php 
Php :: PHP stripos — Find the position of the first occurrence of a case-insensitive substring in a string 
Php :: encode string for csv 
Php :: php listen to select event 
Php :: change php platform of composer 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =