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

Generates semantic classes for each comment element.


Parameters

$css_class

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

Default value: ''

$comment

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

Default value: null

$post

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

Default value: null

$display

(Optional) Whether to print or return the output.<br>

Default value: true


Return

(void|string) Void if $display argument is true, comment classes if $display is false.


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
4.4.0 Added the ability for $comment to also accept a WP_Comment object.
2.7.0 Introduced.