comment_class

Generates semantic classes for each comment element.

Description

(string) comment_class( (string) $class = '', (constant) $comment = null, (constant) $post_id = null, (bool) $echo = true ); 

Returns (string)

If `$echo` is false, the class will be returned. Void otherwise.

Parameters (4)

0. $class — Optional. (string) => ''
One or more classes to add to the class list. Default empty.
1. $comment — Optional. (constant) => null
Comment ID or WP_Comment object. Default current comment.
2. $post_id — Optional. (constant) => null
Post ID or WP_Post object. Default current post.
3. $echo — Optional. (bool) => true
Whether to cho or return the output. Default true.

Usage

  1. if ( !function_exists( 'comment_class' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment-template.php'; 
  3.  
  4. // Optional. One or more classes to add to the class list. 
  5. // Default empty. 
  6. $class = ''; 
  7.  
  8. // Comment ID or WP_Comment object. Default current comment. 
  9. $comment = null; 
  10.  
  11. // Post ID or WP_Post object. Default current post. 
  12. $post_id = null; 
  13.  
  14. // Optional. Whether to cho or return the output. 
  15. // Default true. 
  16. $echo = true; 
  17.  
  18. // NOTICE! Understand what this does before running. 
  19. $result = comment_class($class, $comment, $post_id, $echo); 
  20.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/comment-template.php  
  1. function comment_class( $class = '', $comment = null, $post_id = null, $echo = true ) { 
  2. // Separates classes with a single space, collates classes for comment DIV 
  3. $class = 'class="' . join( ' ', get_comment_class( $class, $comment, $post_id ) ) . '"'; 
  4. if ( $echo) 
  5. echo $class; 
  6. else 
  7. return $class;