Title: comment_class
Published: April 25, 2014
Last modified: April 28, 2025

---

# apply_filters( ‘comment_class’, string[] $classes, string[] $css_class, string $comment_id, WP_Comment $comment, int|WP_Post $post )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/comment_class/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/comment_class/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/comment_class/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/comment_class/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/comment_class/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/comment_class/?output_format=md#wp--skip-link--target)

Filters the returned CSS classes for the current comment.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/comment_class/?output_format=md#parameters)󠁿

 `$classes`string[]

An array of comment classes.

`$css_class`string[]

An array of additional classes added to the list.

`$comment_id`string

The comment ID as a numeric string.

`$comment`[WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)

The comment object.

`$post`int|[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)

The post ID or [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
object.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/comment_class/?output_format=md#source)󠁿

    ```php
    return apply_filters( 'comment_class', $classes, $css_class, $comment->comment_ID, $comment, $post );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/comment-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/comment-template.php#L599)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/comment-template.php#L599-L599)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/comment_class/?output_format=md#related)󠁿

| Used by | Description | 
| [get_comment_class()](https://developer.wordpress.org/reference/functions/get_comment_class/)`wp-includes/comment-template.php` |

Returns the classes for the comment div as an array.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/comment_class/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/comment_class/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/comment_class/?output_format=md#comment-content-7095)
 2.    [Noruzzaman](https://profiles.wordpress.org/noruzzaman/)  [  2 years ago  ](https://developer.wordpress.org/reference/hooks/comment_class/#comment-7095)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fcomment_class%2F%23comment-7095)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fcomment_class%2F%23comment-7095)
 4.  we will walk through how to use `apply_filters` with `comment_class` to customize
     the CSS classes for comments in WordPress.
 5.  **Examples One**
 6.      ```php
         function wpdocs_comment_class_filter1( $classes, $class, $comment_id, $comment ) {
             // For example, add a custom class to comments by the post author
             if ( $comment->user_id === $post->post_author ) {
                 $classes[] = 'comment-by-post-author';
             }
             return $classes;
         }
         add_filter( 'comment_class', 'wpdocs_comment_class_filter1', 10, 4 );
         ```
     
 7.  **Examples Two**
 8.      ```php
         function wpdocs_comment_class_filter2( $classes, $class, $comment_id, $comment ) {
             // Add a custom class to comments by users with a specific email domain
             if ( strpos( $comment->comment_author_email, '@example.com' ) !== false ) {
                 $classes[] = 'comment-by-example-domain';
             }
             return $classes;
         }
     
         add_filter( 'comment_class', 'wpdocs_comment_class_filter2', 10, 4 );
         ```
     
 9.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fcomment_class%2F%3Freplytocom%3D7095%23feedback-editor-7095)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fcomment_class%2F)
before being able to contribute a note or feedback.