comment_class( string|array $class = '', int|WP_Comment $comment = null, int|WP_Post $post_id = null, bool $echo = true )

Generates semantic classes for each comment element.


Parameters

$class

(Optional) One or more classes to add to the class list.

Default value: ''

$comment

(Optional) Comment ID or WP_Comment object. Default current comment.

Default value: null

$post_id

(Optional) Post ID or WP_Post object. Default current post.

Default value: null

$echo

(Optional) Whether to cho or return the output.

Default value: true


Return

(string) If $echo is false, the class will be returned. Void otherwise.


Source

File: wp-includes/comment-template.php

function comment_class( $class = '', $comment = null, $post_id = null, $echo = true ) {
	// Separates classes with a single space, collates classes for comment DIV
	$class = 'class="' . join( ' ', get_comment_class( $class, $comment, $post_id ) ) . '"';
	if ( $echo)
		echo $class;
	else
		return $class;
}


Changelog

Changelog
Version Description
WP-4.4.0 Added the ability for $comment to also accept a WP_Comment object.
WP-2.7.0 Introduced.