# comment_class()

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

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

## Сигнатура

```php
comment_class( string|string[] $css_class = '', int|WP_Comment $comment = null, int|WP_Post $post = null, bool $display = true ): void|string
```

## Описание

Формирует семантические классы для каждого элемента комментария.

## Параметры

- `$css_class` `string|string[]` — необязательный, по умолчанию `''`. Один или несколько классов для добавления в список классов.
- `$comment` `int|WP_Comment` — необязательный, по умолчанию `null`. ID комментария или объект WP_Comment. По умолчанию — текущий комментарий.
- `$post` `int|WP_Post` — необязательный, по умолчанию `null`. ID записи или объект WP_Post. По умолчанию — текущая запись.
- `$display` `bool` — необязательный, по умолчанию `true`. Выводить результат или возвращать его.

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

`void|string` — $display $display

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

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

```php
function comment_class( $css_class = '', $comment = null, $post = null, $display = true ) {
	// Separates classes with a single space, collates classes for comment DIV.
	$css_class = 'class="' . implode( ' ', get_comment_class( $css_class, $comment, $post ) ) . '"';

	if ( $display ) {
		echo $css_class;
	} else {
		return $css_class;
	}
}
```

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

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

## Связанные

Использует: [`get_comment_class`](https://chugunov.pro/api-wordpress/functions/get_comment_class/).
Используется в: [`_wp_dashboard_recent_comments_row`](https://chugunov.pro/api-wordpress/functions/_wp_dashboard_recent_comments_row/), `Walker_Comment::comment`, `Walker_Comment::html5_comment`, `Walker_Comment::ping`.

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