Uses
Uses | Description |
---|---|
wp-includes/comment-template.php: get_comment_class() | Returns the classes for the comment div as an array. |
Generates semantic classes for each comment element.
(string|array) (Optional) One or more classes to add to the class list.
Default value: ''
(int|WP_Comment) (Optional) Comment ID or WP_Comment object. Default current comment.
Default value: null
(int|WP_Post) (Optional) Post ID or WP_Post object. Default current post.
Default value: null
(bool) (Optional) Whether to echo or return the output.
Default value: true
(void|string) Void if $echo
argument is true, comment classes if $echo
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_alt
For 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.
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; } }
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