WordPress大学的用户注册需要填写昵称,但是后台用户列表默认是没有显示昵称的,今天就分享下实现的方法。
将下面的代码添加到主题的 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’]); //移除“姓名”这一栏
RSS