Using WordPress ‘manage_users_custom_column’ PHP filter

The manage_users_custom_column WordPress PHP filter allows you to customize the display output of custom columns in the Users list table.

Usage

add_filter('manage_users_custom_column', 'your_custom_function', 10, 3);
function your_custom_function($output, $column_name, $user_id) {
    // your custom code here
    return $output;
}

Parameters

  • $output (string) – Custom column output. Default empty.
  • $column_name (string) – Column name.
  • $user_id (int) – ID of the currently-listed user.

More information

See WordPress Developer Resources: manage_users_custom_column

Examples

Add and display a custom column for user registration date

// Add a custom column to the Users list table
add_filter('manage_users_columns', 'add_registration_date_column');
function add_registration_date_column($columns) {
    $columns['registration_date'] = 'Registration Date';
    return $columns;
}

// Display the custom column content
add_filter('manage_users_custom_column', 'show_registration_date_column', 10, 3);
function show_registration_date_column($output, $column_name, $user_id) {
    if ('registration_date' === $column_name) {
        $user = get_userdata($user_id);
        $output = $user->user_registered;
    }
    return $output;
}

Add and display a custom column for user’s total published posts

// Add a custom column to the Users list table
add_filter('manage_users_columns', 'add_total_posts_column');
function add_total_posts_column($columns) {
    $columns['total_posts'] = 'Total Posts';
    return $columns;
}

// Display the custom column content
add_filter('manage_users_custom_column', 'show_total_posts_column', 10, 3);
function show_total_posts_column($output, $column_name, $user_id) {
    if ('total_posts' === $column_name) {
        $user_post_count = count_user_posts($user_id);
        $output = $user_post_count;
    }
    return $output;
}

Add and display a custom column for user’s last login time

// Add a custom column to the Users list table
add_filter('manage_users_columns', 'add_last_login_column');
function add_last_login_column($columns) {
    $columns['last_login'] = 'Last Login';
    return $columns;
}

// Display the custom column content
add_filter('manage_users_custom_column', 'show_last_login_column', 10, 3);
function show_last_login_column($output, $column_name, $user_id) {
    if ('last_login' === $column_name) {
        $last_login = get_user_meta($user_id, 'last_login', true);
        $output = $last_login ? date('Y-m-d H:i:s', strtotime($last_login)) : 'Never';
    }
    return $output;
}