How can I highlight admin comments?

Basically what I want is to have all comments posted by admins with different background color than the rest, so they’re easily distinguishable.

I wasn’t able to find any plugin that would do this though, and hacking it into the theme doesn’t look very clean.

Read More

Any suggestions?

Related posts

Leave a Reply

3 comments

  1. By default WordPress already adds user/admin/post author specific CSS to comments with the following three elements.

    #byuser
    #comment-author-admin
    .bypostauthor

    So you can just add something like #comment-author-admin {background-color;blue;} to your stylesheet.

  2. Assuming that your Theme:

    1. Uses the default comment-list markup, via wp_list_comments(), or
    2. Manually applies the <?php comment_class(); ?> template tag appropriately

    …then all you need to do in order to style author comments is to target the CSS class .bypostauthor.

    So, if, in your case, “author” = “admin”, then you’re all set.

    However, if your site has multiple authors, and/or multiple admins, then that won’t be sufficient.

    Fortunately, the comment_class() template tag can accept an argument, used to pass additional classes (it is also passed through the comment_class filter, but that is more difficult to use in this case).

    So, try something like this:

    $additional_comment_classes = '';
    
    if ( user_can( $comment->user_id, 'administrator' ) ) {
        $additional_comment_classes = ' byadmin';
    }
    

    Then, when you call <?php comment_class(); ?>, call it as <?php comment_class( $additional_comment_classes ); ?>

    Note: you’ll need to be using a callback to <?php wp_list_comments(); ?> in order to modify comment_class() in this manner. If you don’t want to go that route, then you’ll need to add the class via the comment_class filter.

  3. Open your style.css on your template folder and add this:

    .authorstyle { background-color: #B3FFCC !important; }
    

    Now open your comments.php and find code that should look something like this:

    <li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>"></li>
    

    and replace it with this code:

    <li class="<?php if ($comment->user_id == /*Give Author ID here*/) $oddcomment = "authorstyle"; echo $oddcomment; ?>"></li>