DEV Community

Cover image for How to Highlight Author Comments in WordPress
Kevinleary.net
Kevinleary.net

Posted on Originally published at kevinleary.net

How to Highlight Author Comments in WordPress

To highlight comments posted by the author in WordPress, add the following code to the comments.php file in your WordPress template:

 // Author Comments
if (1 == $comment->user_id) { ?>
        <li id="comment-<?php comment_ID(); ?>" class="authcomment">
<?php } else { ?>
        <li id="comment-<?php comment_ID(); ?>">
<?php } 
Enter fullscreen mode Exit fullscreen mode

For reference, the full comment structure I am using for kevinleary.net is:

<ol id="commentlist">
<?php foreach ($comments as $comment) : ?>

<?php // Author Comments
if (1 == $comment->user_id) { ?>
    <li id="comment-<?php comment_ID(); ?>" class="authcomment">
<?php } else { ?>
    <li id="comment-<?php comment_ID(); ?>">
<?php } ?>

        <p>
            <cite><strong class="author"><?php comment_author_link() ?></strong> / <?php comment_date() ?> / <a href="#comment-<?php comment_ID() ?>"><?php comment_time() ?></a><?php edit_comment_link(__(" / Edit")); ?></cite>
        </p>

        <div class="commentbox">
            <?php echo get_avatar( $comment, 32 ); ?>
            <?php comment_text() ?>
        </div>

    </li>

<?php endforeach; ?>
</ol>
Enter fullscreen mode Exit fullscreen mode

Now simply style #commentlist li.authcomment and your done.

Top comments (0)