Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

When i go to wp-admin/users.php, in the second column i can see the users full name, however, its not in the right order. In Hungary, we use a different name order: http://en.wikipedia.org/wiki/Hungarian_names

So i need to change the name from "First name - Last name" to "Last name - First name"

How can i do this?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

You can't alter the default Name column, but what you can do is hide it and create your own custom column.

First, we add the action and filter on admin_init that will add and manage our new column:

function wpa66544_user_custom_column_init(){
    add_filter( 'manage_users_columns', 'wpa66544_user_add_column' );    
    add_action( 'manage_users_custom_column', 'wpa66544_user_manage_column', 100, 3 );
}
add_action( 'admin_init', 'wpa66544_user_custom_column_init' );

Next, the function hooked to our filter above which removes the default name column and adds our own custom column:

function wpa66544_user_add_column( $columns ) {
    // hide the default name column
    unset( $columns['name'] );

    // add our custom name column
    $columns['custom_name']  = 'Name';        
    return $columns;
}

Last, the function hooked to the action in the first step which outputs the value of the column for each user:

function wpa66544_user_manage_column( $val, $column_name, $user_id ) {
    $last_first = '';
    if ( 'custom_name' == $column_name ):
        $first_name = get_the_author_meta( 'first_name', $user_id );
        $last_name = get_the_author_meta( 'last_name', $user_id );
        $last_first = $last_name . ' ' . $first_name;
    endif;
    return $last_first;
}

The one thing missing here is that the column is not sortable. I haven't quite figured out how to do this, though I know the possible method is via the pre_user_query action. It seems the SQL has to be modified directly, as the normal means of making a column sortable won't work in this instance. first/last name are user meta, and you can't order by user meta within this context of a user query.

It also seems that the default Name column is also not sortable anyway, clicking the Name header just does the same thing as clicking the username header- sorts by username, so I suppose you're not really losing any functionality here!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.