• Resolved PSS

    (@airtasker6)


    Hi,

    I was of the believe that post comments on the frontend should show the comment author’s display name instead of their first and/or last names. A recent comment submission by a user who has a first and last name on their WP profile has the comment displaying the user’s first name instead of their display name.

    I say “frontend” because when we click on “Edit” for the particular comment in WP admin, it shows the author’s display name under the comment “Name” field. All users have their display name set as their username because we have always had a function that automatically actions that.

    I don’t know if it is usual for WP comments to display a user’s first and/or last name when it is available on the user profile or if it is meant to display the user’s display name. How do we go about fixing this?

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    What is displayed can vary by theme. Default behavior is if the comment_author field is not empty, use whatever the saved value is. If it is empty, try to get the user’s data from the DB. If there’s such a user, use their display name, otherwise show “Anonymous”.

    What’s in the comment_author field depends on whether they were logged in at the time of making the comment or not. If logged in, it should be their chosen display name when they made the comment. If not, it’s whatever they provided in the “Name” field.

    If users change their display name in their profile, earlier comments are not updated to reflect their new preference.

    As I said though, this can vary by theme. If you’re getting unexpected names it could be due to your theme.

    Thread Starter PSS

    (@airtasker6)

    Hi @bcworkz

    Thanks for the reply. Maybe I didn’t explain myself clearly enough.

    All comments are posted by logged-in users only. All comment-author fields are filled with the user’s display name, including this comment that is showing the user’s first name instead of the display name which is in the comment-author field.

    I don’t know that the Blank Canvas theme would be doing this. Is there any easy way to change this with PHP?

    Moderator bcworkz

    (@bcworkz)

    Assuming your theme calls list_comments() or something similar you could use the “get_comment_author” filter to alter the author’s name as you wish. Your callback is passed the name according to WP, the comment ID, and the WP_Comment object. You should be able to get adequate data from the object to access the author’s data since they are always logged in.

    If your theme does something else, you’ll need to look at the related source code to see what’s possible.

    Thread Starter PSS

    (@airtasker6)

    Hi @bcworkz

    I’ll look into that fix. Thanks for your assistance with this.

    Cheers.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Comments Showing User’s First Name’ is closed to new replies.