Add custom Column to Users list table on WordPress
•
1 min read
Was working on this, thought to blog.
Sometimes it's needed to add extra column on user table to show extra property file a custom meta field or something like this.
Let's say you want to list a column called Customer Since
on user table which will display the registration date of your user.
Okay we'll do it now.
To achieve this we will have to use to action hook called manage_users_columns
and manage_users_custom_column
First will have to add the extra column on the table.
function register_custom_user_column($columns) {
$columns['customer_since'] = 'Customer Since';
return $columns;
}
Now generate the value
function register_custom_user_column_view($value, $column_name, $user_id) {
$user_info = get_userdata( $user_id );
if($column_name == 'customer_since') return $user_info->user_registered;
return $value;
}
Finally hook them
add_action('manage_users_columns', 'register_custom_user_column');
add_action('manage_users_custom_column', 'register_custom_user_column_view', 10, 3);
Aaand, that's it.