Add custom column to Users admin panel

There is default 5 columns named Username Name Email Role Posts in USERS.Now I want to add one more column with his con

There is default 5 columns named Username Name Email Role Posts in USERS. Now I want to add one more column with his contact number.

How can I achieve this??

There is default 5 columns named Username Name Email Role Posts in USERS. Now I want to add one more column with his contact number.

How can I achieve this??

Share Improve this question edited Sep 6, 2014 at 17:02 helgatheviking 14.5k8 gold badges64 silver badges115 bronze badges asked Sep 6, 2014 at 11:00 Rohil_PHPBeginnerRohil_PHPBeginner 7082 gold badges6 silver badges14 bronze badges 5
  • Do you have phone number setup? I mean can your user add phone numbers in their profile? – Robert hue Commented Sep 6, 2014 at 11:08
  • no .. I just want to know how to add .. its not fix that contact number only .. its can b just a blank column also – Rohil_PHPBeginner Commented Sep 6, 2014 at 11:09
  • 1 If your site had a lot of custom columns, you might be interested in a plugin called Admin Columns. – somebodysomewhere Commented Jun 1, 2016 at 19:13
  • you can see this blog with detailed explanation tekina.info/… – Aniket Singh Commented Sep 12, 2017 at 17:20
  • For the non-coders, there is a plugin Advanced Custom Fields. (Google leads to this page, too. Newbies might not know all plugins of WordPress) – koppor Commented Jul 12, 2020 at 13:37
Add a comment  | 

1 Answer 1

Reset to default 68

Ok, Here is the code to allow your users to add phone numbers. Paste this full code in functions.php file. This will add new field on user profile for "Phone Number" and add a column user table on WordPress admin for phone.

function new_contact_methods( $contactmethods ) {
    $contactmethods['phone'] = 'Phone Number';
    return $contactmethods;
}
add_filter( 'user_contactmethods', 'new_contact_methods', 10, 1 );


function new_modify_user_table( $column ) {
    $column['phone'] = 'Phone';
    return $column;
}
add_filter( 'manage_users_columns', 'new_modify_user_table' );

function new_modify_user_table_row( $val, $column_name, $user_id ) {
    switch ($column_name) {
        case 'phone' :
            return get_the_author_meta( 'phone', $user_id );
        default:
    }
    return $val;
}
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row', 10, 3 );

EDIT

To add two columns you need to make some changes. Compare both codes to understand.

function new_modify_user_table( $column ) {
    $column['phone'] = 'Phone';
    $column['xyz'] = 'XYZ';
    return $column;
}
add_filter( 'manage_users_columns', 'new_modify_user_table' );

function new_modify_user_table_row( $val, $column_name, $user_id ) {
    switch ($column_name) {
        case 'phone' :
            return get_the_author_meta( 'phone', $user_id );
        case 'xyz' :
            return '';
        default:
    }
    return $val;
}
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row', 10, 3 );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745431947a4627431.html

相关推荐

  • Add custom column to Users admin panel

    There is default 5 columns named Username Name Email Role Posts in USERS.Now I want to add one more column with his con

    15小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信