Timber Logo

You are reading the documentation for Timber v2.x. Switch to the documentation for Timber v1.x.


Class provides different text-related functions commonly used in WordPress development

Overview #

Methods #

NameReturn TypeSummary/Returns
remove_tags()null or string or string[]
trim_characters()stringTrims text to a certain number of characters.

Returns: trimmed text.

Class Methods #

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.

$textstringText to trim.
$num_charsintNumber of characters. Default is 60.
$morestringWhat 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

$morestring or null or falsetext to appear in "Read more...". Null to use default, false to hide

remove_tags() #

remove_tags( mixed $string, array $tags = [] )

Returns: null|string|string[]