# get_comment_excerpt()

URL: https://chugunov.pro/api-wordpress/functions/get_comment_excerpt/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 1.5.0.

## Сигнатура

```php
get_comment_excerpt( int|WP_Comment $comment_id ): string
```

## Описание

Возвращает не более 20 слов, при необходимости добавляя многоточие.

## Параметры

- `$comment_id` `int|WP_Comment` — необязательный. WP_Comment или ID комментария, для которого нужно получить отрывок.
  
  По умолчанию — текущий комментарий.

## Возвращаемое значение

`string`

## Исходный код

Файл: `wp-includes/comment-template.php:658`

```php
function get_comment_excerpt( $comment_id = 0 ) {
	$comment = get_comment( $comment_id );

	if ( ! post_password_required( $comment->comment_post_ID ) ) {
		$comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );
	} else {
		$comment_text = __( 'Password protected' );
	}

	/* translators: Maximum number of words used in a comment excerpt. */
	$comment_excerpt_length = (int) _x( '20', 'comment_excerpt_length' );

	/**
	 * Filters the maximum number of words used in the comment excerpt.
	 *
	 * @since 4.4.0
	 *
	 * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt.
	 */
	$comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length );

	$comment_excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '&hellip;' );

	/**
	 * Filters the retrieved comment excerpt.
	 *
	 * @since 1.5.0
	 * @since 4.1.0 The `$comment_id` and `$comment` parameters were added.
	 *
	 * @param string     $comment_excerpt The comment excerpt text.
	 * @param string     $comment_id      The comment ID as a numeric string.
	 * @param WP_Comment $comment         The comment object.
	 */
	return apply_filters( 'get_comment_excerpt', $comment_excerpt, $comment->comment_ID, $comment );
}
```

## История изменений

- 4.4.0 — Added the ability for $comment_id to also accept a WP_Comment object.
- 1.5.0 — Introduced.

## Связанные

Использует: [`wp_trim_words`](https://chugunov.pro/api-wordpress/functions/wp_trim_words/), [`post_password_required`](https://chugunov.pro/api-wordpress/functions/post_password_required/), [`__`](https://chugunov.pro/api-wordpress/functions/__/), [`_x`](https://chugunov.pro/api-wordpress/functions/_x/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`get_comment`](https://chugunov.pro/api-wordpress/functions/get_comment/).
Используется в: [`comment_excerpt`](https://chugunov.pro/api-wordpress/functions/comment_excerpt/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/get_comment_excerpt/
