Adding extra column in WordPress users page

WordPress allows us to add custom fields for users using add_user_metaThese custom fields can be shown in the users page as an additional column.

Step 1:

You can add the column using WordPress Filters as given below

add_filter( 'manage_users_columns', 'add_user_column' );

This will call the function add_user_column, which can take one parameter $column. $column is the array of columns in which you may add the additional column name as an array element

function add_user_column( $column ) { 
$column['company'] = 'Company';
return $column;
}

I have added a column with key ‘company’ and value ‘Company’. The function returns the column array with an additional element. This will create a column with head ‘Company’. If you are getting it to work till this, you may go ahead to the next step.

Result

Step 2:

Now you need to show the user custom field in the column. User custom field can be retrieved using get_user_meta.

WordPress filter should be used to insert the custom field values into the column

add_filter( 'manage_users_custom_column', 'add_users_row', 10, 3 );

Above filter will call the function add_users_row. Function can take 3 parameters, and it should return appropriate custom field as given below.

function add_users_row( $empty='', $column_name, $user_id) {
   switch ($column_name) {
        case 'company' :
            return get_user_meta($user_id, 'company', true);
            break;
        default:
   }
}

Result:

This will add extra column to the Users page.