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.
- $text = apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text );
- if ( !empty( $text ) ) {
- // everything has led up to this point...
- }
- The following example is for adding a hook callback.
- // define the wp_trim_words callback
- function filter_wp_trim_words( $text, $num_words, $more, $original_text ) {
- // make filter magic happen here...
- return $text;
- };
- // add the filter
- add_filter( 'wp_trim_words', 'filter_wp_trim_words', 10, 4 );
- To remove a hook callback, use the example below.
- // remove the filter
- 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
- return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text );