WordPress at Your Fingertips

comment_class() WP 1.0

Generates semantic classes for each comment element.

1 time — 0.001315 sec (very slow) | 50000 times — 2.64 sec (fast) | PHP 7.0.5, WP 4.4.2

No Hooks.


null|String. Void if $echo argument is true, comment classes if $echo is false.


comment_class( $class, $comment, $post_id, $echo );
One or more classes to add to the class list.
Default: ''
Comment ID or WP_Comment object.
Default: current comment
Post ID or WP_Post object.
Default: current post
Whether to echo or return the output.
Default: true


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

Code of comment_class() WP 5.8

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

	if ( $echo ) {
		echo $class;
	} else {
		return $class;

From tag: Decor (design, layout, styling, class)

More from category: Comments Loop

More from Template Tags: Comments

No comments
    Log In