0

I would like to add extra markup to a comment made by the site admin/post author. Is there a check for this and how would I add it to my code below?

Basically, if the comment is from the post author I would like to add HTML next to their name (Author or Admin).

Thanks

            <div class="comment-meta commentmetadata ">         
                <?php printf(__('<cite class="fn">%s</cite> <span class="says">said on</span>'), get_comment_author_link()) ?>
                <a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
                <?php
                    printf( __('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'  ','' );
                ?>
        </div>

2 Answers 2

0

If you use the comment_class function to add classes to each comment, comments by the post's author can be styled via the bypostauthor class.

You can alternately match the comment ID against the post ID:

global $post;
if( $comment->user_id === $post->post_author ) {
    // is author comment
}
2
  • I'm getting a undeclared variable warning. Notice: Undefined variable: post in /Users/huw/Sites/mamp/MyProjects/canvas/wp-content/themes/canvas/functions.php on line 252 Notice: Trying to get property of non-object in /Users/huw/Sites/mamp/MyProjects/canvas/wp-content/themes/canvas/functions.php on line 252 Commented Dec 1, 2013 at 18:45
  • you have to globalize $post if you're using it within a function, see edit above.
    – Milo
    Commented Dec 1, 2013 at 19:26
0

I have very simple solution to this. Just add this code to your theme’s comments.php file

<?php
if (1 == $comment->user_id)
  echo 'author';
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.