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
if ( !function_exists( 'comment_class' ) ) { require_once ABSPATH . WPINC . '/comment-template.php'; } // Optional. One or more classes to add to the class list. // Default empty. $class = ''; // Comment ID or WP_Comment object. Default current comment. $comment = null; // Post ID or WP_Post object. Default current post. $post_id = null; // Optional. Whether to cho or return the output. // Default true. $echo = true; // NOTICE! Understand what this does before running. $result = comment_class($class, $comment, $post_id, $echo);
Defined (1)
The function is defined in the following location(s).
- /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;
- }