WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What's the best way of checking if my commenter is also the author of the post that he post comment on?

I know there's a css way (.byauthor), but how about PHP? How to compare post author with comment author? I was trying with is_author(), the_author() and comment_author() but it just doesn't look right (what if somebody uses the same nickname as author?).

Here's my code for now:

<?php if(get_the_author() == get_comment_author()) _e( 'Author', 'theme' ) ?>
share|improve this question
up vote 5 down vote accepted

Not sure what you are meaning to do but, if you take a look at the get_comment_class() function that is responsible for generating the .bypostauthor class you can see how it determines if the commenter is the author

if ( $post = get_post($post_id) ) {
            if ( $comment->user_id === $post->post_author )
                $classes[] = 'bypostauthor';

You should be able to use this to do something similar.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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