WordPress 後臺用戶列表顯示用戶昵稱

WordPress大學的用戶註冊需要填寫昵稱,但是後臺用戶列表默認是沒有顯示昵稱的,今天就分享下實現的方法。

add-user-nickname-column-wpdaxue_com

將下面的代碼添加到主題的 functions.php 即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
 * WordPress 後臺用戶列表顯示用戶昵稱
 * https://www.wpdaxue.com/add-user-nickname-column.html
 */
add_filter('manage_users_columns', 'add_user_nickname_column');
function add_user_nickname_column($columns) {
	$columns['user_nickname'] = '昵稱';
	return $columns;
}
add_action('manage_users_custom_column',  'show_user_nickname_column_content', 20, 3);
function show_user_nickname_column_content($value, $column_name, $user_id) {
	$user = get_userdata( $user_id );
	$user_nickname = $user->nickname;
	if ( 'user_nickname' == $column_name )
		return $user_nickname;
	return $value;
}

/**
* WordPress 後臺用戶列表顯示用戶昵稱
* https://www.wpdaxue.com/add-user-nickname-column.html
*/
add_filter(‘manage_users_columns’, ‘add_user_nickname_column’);
function add_user_nickname_column($columns) {
$columns[‘user_nickname’] = ‘昵稱’;
return $columns;
}
add_action(‘manage_users_custom_column’, ‘show_user_nickname_column_content’, 20, 3);
function show_user_nickname_column_content($value, $column_name, $user_id) {
$user = get_userdata( $user_id );
$user_nickname = $user->nickname;
if ( ‘user_nickname’ == $column_name )
return $user_nickname;
return $value;
}

如果你需要去除“姓名”這一欄,在上面的第 7 行下面添加以下代碼即可:

1
unset($columns['name']); //移除“姓名”這一欄

unset($columns[‘name’]); //移除“姓名”這一欄

發佈留言