How do I display the commentor's first name and last name in the comments?... rather than their username as currently shows.


This will get you a first name + last name combination if available, or just the first name or last name if that's all your user submitted.

This assumes you're interested in registered user's names. If you're going to add first and last names to your commenting form... or treat first + last name as "display name" from the back end forward (so possibly not just in commenting forms), either would be something different!

For theme functions.php or plug-in:

add_filter( 'get_comment_author', 'wpse_use_user_real_name', 10, 3 ) ;

//use registered commenter first and/or last names if available
function wpse_use_user_real_name( $author, $comment_id, $comment ) {

    $firstname = '' ;
    $lastname = '' ;

    //returns 0 for unregistered commenters
    $user_id = $comment->user_id ;

    if ( $user_id ) {

        $user_object = get_userdata( $user_id ) ;

        $firstname = $user_object->user_firstname ;

        $lastname = $user_object->user_lastname ; 


    if ( $firstname || $lastname ) {

        $author = $firstname . ' ' . $lastname ; 

        //remove blank space if one of two names is missing
        $author = trim( $author ) ;


    return $author ;


Your results may of course vary depending on your installation and whatever particular requirements you may have added 1) for commenting (i.e., "anyone" vs "registered only") and 2) for signing up (are First and Last Name required to register?).

Additionally, in a full installation, you might want to adjust the user profile page, where the user selects a "display name." If you're going to display firstname/lastname instead then it'd be best to deal with that one way or another - by restricting choices, for example, or by adjusting labels and instructions.


Take a look at the 'callback' argument of the function wp_list_comments. You can set a own function to render the comment list: https://codex.wordpress.org/Function_Reference/wp_list_comments.

After some googling, i found a great and complete article that may help you: https://blog.josemcastaneda.com/2013/05/29/custom-comment/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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