You were nearly there with your first piece of code. For this to completely work, you’ll need to get a list of the comment classes and check your class against that list. If your class exists in that returned list, you can something, if not, do something else
Use get_comment_class()
to retrieve that list. Here is an example
$classes = get_comment_class();
if(in_array('bypostauthor',$classes)) {
// do something for bypostauthor class
} else {
// do something else if bypostauthor class don't exist
}
EDIT 2
Your problem is pure syntax. Your HTML needs to be between single quotes ('
), otherwise it is read as php, which is invalid php, caussing the syntax error. Check my example below
function author_tag() {
$classes = get_comment_class();
if(in_array('bypostauthor',$classes)) {
$output="<div class="author-tag"><p>AUTHOR</p></div>";
} else {
$output="<div class="author-tag"><p>NOT AUTHOR</p></div>";
}
return $output;
}
I would advice you to get a good syntax highligher, this will help you a lot with invalid syntaxes