buddyboss_global_search_result_intro

Returns highlighted search keyword and trimmed content string with.

Description

(mixed|void) buddyboss_global_search_result_intro( $content, (int) $character_limit = 50 ); 

Returns (mixed|void)

Parameters (2)

0. $content
The content.
1. $character_limit — Optional. (int) => 50
The character limit.

Usage

  1. if ( !function_exists( 'buddyboss_global_search_result_intro' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress-global-search/includes/functions.php'; 
  3.  
  4. // The content. 
  5. $content = null; 
  6.  
  7. // The character limit. 
  8. $character_limit = 50; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = buddyboss_global_search_result_intro($content, $character_limit); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/functions.php  
  1. function buddyboss_global_search_result_intro( $content, $character_limit = 50 ) { 
  2.  
  3. $content = wp_strip_all_tags( $content, true ); 
  4. $search_term = buddyboss_global_search()->search->get_search_term(); 
  5.  
  6. $search_term_position = stripos( $content, $search_term ); 
  7.  
  8. if( $search_term_position !== false ) { 
  9. $shortened_content = '...' . substr( $content, $search_term_position, $character_limit ); 
  10. //highlight search keyword 
  11.  
  12. $shortened_content = str_ireplace( $search_term, "<strong>" . $search_term . "</strong>", $shortened_content ); 
  13. } else { 
  14. $shortened_content = substr( $content, 0, $character_limit ); 
  15.  
  16. if( strlen($content)> $character_limit ) 
  17. $shortened_content .= '...'; 
  18.  
  19. $content = $shortened_content; 
  20.  
  21. return apply_filters( 'buddyboss_global_search_result_intro', $content );