Home / Admin / Show User ID
Duplicate Snippet

Embed Snippet on Your Site

Show User ID

List user ID column after username on admin user table.

Code Preview
php
<?php
// 1. Add the ID column after the Username column
function add_user_id_column($columns) {
    $new_columns = array();
    foreach ($columns as $key => $value) {
        $new_columns[$key] = $value;
        // Insert 'user_id' column right after 'username'
        if ($key === 'username') {
            $new_columns['user_id'] = 'ID';
        }
    }
    return $new_columns;
}
add_filter('manage_users_columns', 'add_user_id_column');
// 2. Populate the ID column with the actual user ID
function show_user_id_column_content($value, $column_name, $user_id) {
    if ($column_name === 'user_id') {
        return $user_id;
    }
    return $value;
}
add_filter('manage_users_custom_column', 'show_user_id_column_content', 10, 3);   

Comments

Add a Comment