If you want to output some data (such as biographical info or personal website) for the person who commented on WordPress post or page, you should be able to get the user ID so you could use it for the_author_meta() function. One of the ways to do it is by using the following code – the first line returns commenter ID, while other lines returns some specific data:
1 2 3 4 5 6 |
<?php $user_id=$comment->user_id; ?> <p class="commenter-bio"><?php the_author_meta('description',$user_id); ?></p> <p class="commenter-url"><a href="<?php the_author_meta('user_url',$user_id); ?>" target="_blank"><?php the_author_meta('user_url',$user_id); ?></a></p> |
But at this point, if you’re asking yourself “What is the ID for anonymous commenter”, your question is right on the spot. I believe that this code can be useful only if you allow only registered users to comment on your posts, which was exactly the case I had which that led me to research this method.
Also, even if you allow anyone to post comments on your blog, the $user_id should return 0 for anonymous commenters (whoever is not registered as user, those are).