Before I comment on a blog, I like to take a look at post comments, to see if an author is active on the site. It’s a pet peeve, but I dislike to comment on blogs where the author doesn’t seem to be interested in fostering a community. I guess I like for my input to be read and possibly valued… call me difficult. I will live.
So since it’s something I value highly in blogs I frequent, I make it a point to make sure any blogs I work on make it easy to distinguish author comments in a blog post’s comment thread. While some themes don’t think of this small, but important usability feature, it’s very easy to setup on your own site.
It’s as simple as these 3 steps.
1. Verify comments.php using wp_list_comments(). Since version 2.7.0, WordPress added the wp_list_comments() function. It automatically adds a “comment-author-admin” class to the LI element wrapping the author’s comment.
However, if your theme doesn’t use wp_list_comments() to display the comments, you will need to add your class to the existing list of classes by:
First, registering a filter –
1 |
add_filter('comment_class', "my_new_function", 1 ); |
Second, defining the function-
1 2 3 4 5 6 7 |
function my_new_function($classes) { if (1 == $comment->user_id) { classes[] = "my-css-class"; } return $classes; } |
And change the “1” to match the id of the author you want to highlight.
2. Edit your theme’s style.css to add your new author class:
1 2 3 |
.new-author-comment-class-name { // Add your styling here } |
Make sure to change “new-author-comment-class-name” to use the WordPress default of “comment-author-admin” or whatever you created to replace “my-css-class” in the previous step.
And that’s it! Now you can customize your author comments in any way you want!