워드프레스에서 댓글 표시 이름을 '성 이름'으로 변경하는 방법
add_filter( 'comment_author', 'custom_comment_author', 10, 2 );
function custom_comment_author( $author, $commentID ) {
$comment = get_comment( $commentID );
$user = get_user_by( 'email', $comment->comment_author_email );if( !$user ):
return $author;
else:
$firstname = get_user_meta( $user->id, 'first_name', true );
$lastname = get_user_meta( $user->id, 'last_name', true );if( empty( $firstname ) OR empty( $lastname ) ):
return $author;
else:
return $lastname . $firstname;
endif;
endif;
위의 코드를 테스트해보면 관리자 페이지 표시되는 댓글 사용자의 표시 이름은 원하는 대로 변경되지만 코멘트 폼에서 표시되는 사용자 이름은 아바다(Avada) 테마에서 테스트해보니 변경이 되지 않네요. 그런 경우 댓글 폼 템플릿을 수정해야 할 것 같습니다.