Timber Logo

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

Timber\​TextHelper

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.
trim_words()string

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.

NameTypeDescription
$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

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

remove_tags() #

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

Returns: null|string|string[]

NameTypeDescription
$string
$tagsarray