How can I add information underneath the user’s name on the users.php page?

A Replica Of The Name Column In WP_Users_List_Table

I think we’ll have to remove the current Name column and add in our own column instead.

Here are the steps:

Step #1

First we add in our own custom Name column and then remove the default Name column. Here I use the array slicing trick, mentioned here, to do it in a single sweep:

add_filter( 'manage_users_columns', function( $columns )
{
    return array_slice( $columns, 0, 2, true ) 
        + [ 'mycol' => __( 'Name' ) ] 
        + array_slice( $columns, 3, null, true );
} );

Step #2

Then we need to display the first- and lastname of the corresponding user, together with the extra “Some text here” message:

add_filter( 'manage_users_custom_column', function( $output, $column_name, $user_id )
{
    if( 'mycol' === $column_name )
    {
        $u = new WP_User( $user_id ); 
        if( $u instanceof \WP_User )
        {
            // Default output
            $output .= "$u->first_name $u->last_name";

            // Extra output
            $output .= "<p>Some text here!</p>";

            // Housecleaning
            unset( $u ); 
        }
    }       
    return $output;
}, 10, 3 );   

Step #3

Then we only need to adjust the sortable columns with:

add_filter( 'manage_users_sortable_columns', function( $columns )
{
    $columns['mycol'] = 'name';
    return $columns;
} );

to handle the name sorting, that’s already supported by the public orderby query varaiable:

/wp-admin/users.php?orderby=name&order=asc

and

/wp-admin/users.php?orderby=name&order=desc

Hopefully you can adjust this to your needs.

Leave a Comment