wc_trim_string( string $string, integer $chars = 200, string $suffix = '...' )

Trim a string and append a suffix.


Description Description


Parameters Parameters

$string

(Required) String to trim.

$chars

(Optional) Amount of characters. Defaults to 200.

Default value: 200

$suffix

(Optional) Suffix. Defaults to '...'.

Default value: '...'


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/wc-formatting-functions.php

function wc_trim_string( $string, $chars = 200, $suffix = '...' ) {
	if ( strlen( $string ) > $chars ) {
		if ( function_exists( 'mb_substr' ) ) {
			$string = mb_substr( $string, 0, ( $chars - mb_strlen( $suffix ) ) ) . $suffix;
		} else {
			$string = substr( $string, 0, ( $chars - strlen( $suffix ) ) ) . $suffix;
		}
	}
	return $string;
}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.