wp_trim_words

Filters the text content after words have been trimmed.

Description

apply_filters( 'wp_trim_words', (string) $text, (int) $num_words, (string) $more, (string) $original_text ); 

Parameters (4)

0. $text (string)
The trimmed text.
1. $num_words (int)
The number of words to trim the text to. Default 5.
2. $more — Optional. (string)
An optional string to append to the end of the trimmed text, e.g. ….
3. $original_text (string)
The text before it was trimmed.

Usage

To run the hook, copy the example below.
  1. $text = apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text ); 
  2.  
  3. if ( !empty( $text ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the wp_trim_words callback 
  2. function filter_wp_trim_words( $text, $num_words, $more, $original_text ) { 
  3. // make filter magic happen here... 
  4. return $text
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'wp_trim_words', 'filter_wp_trim_words', 10, 4 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'wp_trim_words', 'filter_wp_trim_words', 10, 4 ); 

Defined (1)

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

/wp-includes/formatting.php  
  1. return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text );