Created
November 1, 2017 16:53
-
-
Save Garconis/5c0652b7e6defc6e7264e7a1706b8ad9 to your computer and use it in GitHub Desktop.
WordPress | Change user Display Name to be their username after login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Replaces default display name to login name (username). As soon as the user logs in, the setting gets changed. | |
add_action( 'wp_login', 'fs_format_user_display_name_on_login' ); | |
function fs_format_user_display_name_on_login( $username ) { | |
$user = get_user_by( 'login', $username ); | |
$userdata = array( | |
'ID' => $user->ID, | |
'display_name' => $user->user_login, | |
); | |
wp_update_user( $userdata ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment