Can anyone help me with adding data to a new User table column that I added?
In the wordpress backend, in the Users section, I added a custom column called "Last Name". Now, I'd like to add last names to that column.
I've looked at this this and this, but nothing has worked.
In my functions.php file, the code below is the closest I've gotten to displaying something on the screen, but the problem is that it's displaying it completely outside of the users list/table (directly above it in fact)
function last_name_value($column_name, $user_id) {
if ( 'lname' == $column_name ) {
echo __('last name here','text-domain');
}
}
add_action('manage_users_custom_column', [$this, 'last_name_value'], 10, 2);
A value of 10 displays 'last name here' above the User table (not where I want it obviously), but I should note that it erases all the data in 5 columns for some reason. Any number below 10 and nothing displays.
I'm sure this is really easy, right? What am I doing wrong?
Can anyone help me with adding data to a new User table column that I added?
In the wordpress backend, in the Users section, I added a custom column called "Last Name". Now, I'd like to add last names to that column.
I've looked at this this and this, but nothing has worked.
In my functions.php file, the code below is the closest I've gotten to displaying something on the screen, but the problem is that it's displaying it completely outside of the users list/table (directly above it in fact)
function last_name_value($column_name, $user_id) {
if ( 'lname' == $column_name ) {
echo __('last name here','text-domain');
}
}
add_action('manage_users_custom_column', [$this, 'last_name_value'], 10, 2);
A value of 10 displays 'last name here' above the User table (not where I want it obviously), but I should note that it erases all the data in 5 columns for some reason. Any number below 10 and nothing displays.
I'm sure this is really easy, right? What am I doing wrong?
Share Improve this question asked Dec 10, 2019 at 2:34 sansaesansae 1892 silver badges10 bronze badges 1- In case you want to be fully customizable, you can use the plugin Advanced Custom Fields. – koppor Commented Jul 9, 2020 at 22:52
1 Answer
Reset to default 1manage_users_custom_column
is a filter hook, so you should useadd_filter()
and notadd_action()
. Which also means you should return the output instead of echoing it.The column name is the second parameter and not the first one — which is the current value for the current column.
So try with:
function last_name_value($output, $column_name, $user_id) {
if ( 'lname' == $column_name ) {
return __('last name here','text-domain');
}
return $output;
}
add_filter('manage_users_custom_column', [$this, 'last_name_value'], 10, 3);