Being able to quickly find the unique ID number of any user in your WordPress database can be very useful, especially if you run a website with lots of users. One of the ways that we can easily find a user’s ID is by customizing the table displayed on the wp-admin/users.php page. We can add a custom column that will display the ID number of every user.
This is a quick tip. Check out more Quick Tips
To add the user ID column, you can either copy this code into your functions.php, or add it as its own plugin.
1 2 3 4 5 6 7 8 9 10 11 12 13 | add_filter('manage_users_columns', 'pippin_add_user_id_column'); function pippin_add_user_id_column($columns) { $columns['user_id'] = 'User ID'; return $columns; } add_action('manage_users_custom_column', 'pippin_show_user_id_column_content', 10, 3); function pippin_show_user_id_column_content($value, $column_name, $user_id) { $user = get_userdata( $user_id ); if ( 'user_id' == $column_name ) return $user_id; return $value; } |
Using the same methods as I have here, you could very easily add custom columns for even more user attributes, such as the user’s comment count.

Thanks for sharing this solution, is there a way to change the order of the column so the user ID can appear as the first column?
Yes, all you need to do is make the ['user_id'] column be the first item in the array. Do you know how to do that?
Hi,
Is there a way to show this column second (after the checkbox and ‘username’ column)?
Also is it possible to make it sortable?
Yes, you can make it the second column. All of the columns shown on the user page are available in the $columns array, so all you have to do is set the “user_id” column to the second index. Does that make sense?
For making it sortable, I’d suggest you read through this thread.
Hi Pippin,
Thanks for your help. I think I have to split the array is this correct? I have no idea how to do that.
I also wasn’t able to get the sorting working from that article.
add_filter('manage_users_columns', 'pippin_add_user_id_column');
function pippin_add_user_id_column($columns) {
$columns['displayname'] = 'Display Name';
return $columns;
}
add_filter( 'manage_users_sortable_columns', 'pippin_add_user_id_column' );
function user_column_orderby( $vars ) {
if ( isset( $vars['orderby'] ) && 'displayname' == $vars['orderby'] ) {
$vars = array_merge( $vars, array(
'meta_key' => 'displayname',
'orderby' => 'meta_value',
'order' => 'asc'
) );
}
return $vars;
}
add_filter( 'request', 'user_column_orderby' );
function add_user_columns( $defaults ) {
$defaults['displayname'] = __('Display Name', 'user-column');
return $defaults;
}
function pippin_show_user_id_column_content($value, $column_name, $user_id) {
$user = get_userdata( $user_id );
if ( 'displayname' == $column_name )
return $user->display_name;
}
add_action('manage_users_custom_column', 'pippin_show_user_id_column_content', 10, 3);
add_filter('manage_users_columns', 'add_user_columns');
Probably the easiest way would be to sort the $columns array. See here for some examples: http://php.net/manual/en/array.sorting.php
How do i upate one particular user colum field on the database?
That’s not relevant to this tutorial, but you will need to look at the update_user_meta() function.
hi pippin,
Your solution is exclacty what I need!
But I dont understand how to implement it..!
tks! Ronnie
Placing this code in your functions.php of your active theme should do it for you.
Be sure to always return
$valuein themanage_users_custom_columncallback so you don’t accidentally overwrite other plugins’ columns.Whoops! Fixed
Thanks pipin , thanks for the code. can you do one help . i need to make it ascending/descending like the columns username,email etc . please reply me.
That goes far beyond the scope of this tutorial, sorry.
How would you modify this code to return the ‘user_description’ field from get_user_meta? I’ve tried, but I keep getting the ID# or error messages:
add_filter('manage_users_columns', 'custom_add_user_id_column');
function custom_add_user_id_column($columns) {
$columns['user_description'] = 'Company / Role';
return $columns;
}
add_action('manage_users_custom_column', 'custom_show_user_id_column_content', 10, 3);
function custom_show_user_id_column_content($value, $column_name, $user_id) {
$user = get_userdata( $user_id );
if ( 'user_description' == $column_name )
return $user_id;
return $value;
}
Change “user_description” to “description”.