get_comment_class()
Gets CSS classes as an array for the DIV tag that wraps each comment in a loop.
For additional description, see comment_class().
Used By: comment_class()
1 time — 0.001342 sec (very slow) | 50000 times — 2.83 sec (fast) | PHP 7.0.5, WP 4.4.2
Hooks from the function
Returns
String[]. Array of strings (CSS classes).
Usage
get_comment_class( $class, $comment_id, $post_id );
- $class(string/array)
- One or more classes to add to the list.
Default: '' - $comment_id(int/WP_Comment)
- ID or comment object.
Default: null (current comment) - $post_id(int/WP_Post)
- ID or post object.
Default: null (current post)
Examples
#1 Get the comment css classes as an array
$arr = get_comment_class( 'myclass', 123, 2 ); print_r( $arr ); /* Array ( [0] => comment [1] => byuser [2] => comment-author-kama [3] => even [4] => thread-even [5] => depth-1 [6] => myclass ) */
To get array as a string, you can join array of classes:
echo implode( ' ', $arr ); // result: comment byuser comment-author-kama even thread-even depth-1 myclass
Notes
- Global. Int.
$comment_alt - Global. Int.
$comment_depth - Global. Int.
$comment_thread_alt
Changelog
| Since 2.7.0 | Introduced. |
| Since 4.4.0 | Added the ability for $comment_id to also accept a WP_Comment object. |