W3cubDocs

/WordPress

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.

Description

Parameters

$class

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

Default value: ''

$comment

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

Default value: null

$post_id

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

Default value: null

$echo

(bool) (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

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

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/comment_class