625
Sometimes, we need to add a new column on the users admin screen sortable. In this blog post you will learn how to add custom column in All users menu in the backend. Here is the code that allows to add custom fields. In this example we would add company name as a custom field. You can also change order of columns. You have to paste this full code in functions.php file.
// This function will also allow you to change order of column
function labotrees_modify_user_table ( $column ) {
$column = array(
"cb" => "",
"username" => "Username",
"name" => "Full Name",
"billing_company" => 'Company Name',
"email" => "E-mail",
"role" => "Role"
);
return $column;
}
add_filter( 'manage_users_columns', 'labotrees_modify_user_table' );
function labotrees_modify_user_table_row ( $val, $column_name, $user_id ) {
switch ($column_name) {
case 'billing_company' :
return get_the_author_meta( 'billing_company', $user_id );
default:
}
return $val;
}
add_filter( 'manage_users_custom_column', 'labotrees_modify_user_table_row', 10, 3 );
Result:
You Might Be Interested In
- How to renaming Woo-commerce menu in admin panel ?
- How to check the role of Current User ?
- How to add custom classes to the body tag in WordPress?
- What is the difference between add_filter and apply_filters?
- How to pass PHP variable to javascript in WordPress?
- How to remove first occurrence of underscore in a string in javascript?
Post Views: 941