Timber\TextHelper
Class provides different text-related functions commonly used in WordPress development
Overview #
Methods #
| Name | Return Type | Summary/Returns |
|---|---|---|
| remove_tags() | null or string or string[] | |
| trim_characters() | string | Trims text to a certain number of characters. Returns: trimmed text. |
| trim_words() | string |
Class Methods #
remove_tags() #
remove_tags( mixed $string, array $tags = [] )
Returns: null|string|string[]
| Name | Type | Description |
|---|---|---|
| $string | mixed | |
| $tags | array |
trim_characters() #
Trims text to a certain number of characters.
This function can be useful for excerpt of the post As opposed to wp_trim_words trims characters that makes text to take the same amount of space in each post for example
since 1.2.0
trim_characters( string $text, int $num_chars = 60, string $more = '…' )
Returns: string trimmed text.
| Name | Type | Description |
|---|---|---|
| $text | string | Text to trim. |
| $num_chars | int | Number of characters. Default is 60. |
| $more | string | What to append if $text needs to be trimmed. Defaults to '…'. |
trim_words() #
trim_words( string $text, int $num_words = 55, string|null|false $more = null, string $allowed_tags = 'p a span b i br blockquote' )
Returns: string
| Name | Type | Description |
|---|---|---|
| $text | string | |
| $num_words | int | |
| $more | string or null or false | text to appear in "Read more...". Null to use default, false to hide |
| $allowed_tags | string |