Generates semantic classes for each comment element.
$css_classstring|string[]optional
Default:''
$commentint|WP_Commentoptional
Default:null
$postint|WP_Postoptional
Default:null
$displaybooloptional
Default:true
$display argument is true, comment classes if $display is false.comment_class() will apply the following classes, based on the following conditions:
comment_class() uses the following global variables. So these variables can be set prior to calling comment_class() to effect the output:
$comment_alt$comment_depth$comment_thread_altFor example, you can force $comment_alt = FALSE if you always want to start with the first comment being even. The comment_class() function will then alternate this variable for you.
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;
}
}
| Version | Description |
|---|---|
| 4.4.0 | Added the ability for $comment to also accept a WP_Comment object. |
| 2.7.0 | Introduced. |
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/comment_class