Yoast\WP\SEO\Schema_Aggregator\Application\Enhancement

Abstract_Schema_Enhancer::trim_content_to_max_length │ protected │ Yoast 1.0

Trims content to a maximum length, attempting to break at word boundaries.

Метод класса: Abstract_Schema_Enhancer{}

Хуков нет.

Возвращает

string. The trimmed content.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->trim_content_to_max_length( $max_length, $content ): string;
$max_length(int) (обязательный)
Maximum length of content.
$content(строка) (обязательный)
The content to trim.

Код Abstract_Schema_Enhancer::trim_content_to_max_length() Yoast 28.9

protected function trim_content_to_max_length( int $max_length, string $content ): string {
	if ( $max_length > 0 && \strlen( $content ) > $max_length ) {
		$content    = \substr( $content, 0, $max_length );
		$last_space = \strrpos( $content, ' ' );
		if ( $last_space !== false && $last_space > ( $max_length * 0.9 ) ) {
			$content = \substr( $content, 0, $last_space );
		}
		$content .= '...';
	}

	return $content;
}