we will walk through how to use apply_filters with comment_class to customize the CSS classes for comments in WordPress.
Examples One
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 );
Examples Two
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 );
You must log in before being able to contribute a note or feedback.
we will walk through how to use
apply_filterswithcomment_classto customize the CSS classes for comments in WordPress.Examples One
Examples Two