Change the default 'Display name publicly as' to username

392 views
Skip to first unread message

suefernandes

unread,
May 15, 2017, 6:13:58 AM5/15/17
to Manchester WordPress User Group
Hi, 

I have a listings site where the client wants all users to be known by their usernames rather than first name and last name.  However the user profile page automatically sets the default of Display name publicly as to be the firstname/last name.  Is there a way to set this to be the username by default? Or would the client need to go in and change this manually for each user, which is obviously not ideal.

Any ideas would be much appreciated.

Sue 

Mike Little

unread,
May 15, 2017, 6:53:40 AM5/15/17
to Manchester WordPress WordPress User Group (MWUG)


There is a filter here you can use

    /**
     * Filters a user's display name before the user is created or updated.
     *
     * @since 2.0.3
     *  
     * @param string $display_name The user's display name.
     */

    $display_name = apply_filters( 'pre_user_display_name', $display_name );


But it doesn't actually supply any other info, e.g. their login name. I think that if you make it blank in that filter, it will default back to their login name as display name.

If that doesn't work, the filter 'insert_user_meta' fires just after the display_name has been written. So at that point you could rewrite display_name using the info passed in this filter.

A little convoluted, but it should work.



Best regards,

Mike



--
Mike Little
WordPress Specialist

Skype: mike.little.zed1
Twitter: @mikelittlezed1

Founder and Director
Zed1.com Limited
https://zed1.com/
Registered in England & Wales, no. 6745562
Reply all
Reply to author
Forward
0 new messages