Timber Logo

Timber\TextHelper

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


Class Methods #

close_tags #

close_tags( string $html )

returns: string

NameTypeDescription
$htmlstring

ends_with #

ends_with( string $haystack, string $needle )

returns: boolean

Does the string in question (haystack)

end with the substring in question (needle)?

NameTypeDescription
$haystackstring
$needlestring

remove_tags #

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

returns: void

NameTypeDescription
$stringmixed
$tagsarray

starts_with #

starts_with( string $haystack, string $needle )

returns: boolean

NameTypeDescription
$haystackstring
$needlestring

trim_characters #

trim_characters( string $text, mixed/int $num_chars=60, string $more="…" )

returns: string trimmed text.

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

NameTypeDescription
$textstringText to trim.
$num_charsmixed/intNumber of characters. Default is 60.
$morestringWhat to append if $text needs to be trimmed. Defaults to '…'.

trim_words #

trim_words( string $text, mixed/int $num_words=55, mixed/string/null/false $more=null, string $allowed_tags="p a span b i br blockquote" )

returns: string

NameTypeDescription
$textstring
$num_wordsmixed/int
$moremixed/string/null/falsetext to appear in "Read more...". Null to use default, false to hide
$allowed_tagsstring