Here’s the way I have always done it. All of this code goes in functions.php. Of course this adds a whole new section to the user profile.
add_action( 'show_user_profile', 'be_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'be_show_extra_profile_fields' );
function be_show_extra_profile_fields( $user ) { ?>
<h3>Extra Contact Information</h3>
<table class="form-table">
<tr>
<th><label for="contact">Contact Number</label></th>
<td>
<input type="text" name="contact" id="contact" value="<?php echo esc_attr( get_the_author_meta( 'contact', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Please enter your phone number.</span>
</td>
</tr>
</table>
<?php }
add_action( 'personal_options_update', 'be_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'be_save_extra_profile_fields' );
function be_save_extra_profile_fields( $user_id ) {
if ( ! current_user_can( 'edit_user', $user_id ) ) {
return false;
}
update_usermeta( $user_id, 'contact', esc_attr( $_POST['contact'] ) );
}
Alternatively If you want to add some contact methods to the already existing section in the user profile you can use the following and it’s a little cleaner. Below is the function i usually use to get rid of outdated social platforms and add some new ones for users.
add_filter( 'user_contactmethods', 'be_hide_profile_fields', 10, 1 );
function be_hide_profile_fields( $contactmethods ) {
unset($contactmethods['aim']);
unset($contactmethods['jabber']);
unset($contactmethods['yim']);
$contactmethods['twitter'] = 'Twitter';
$contactmethods['facebook'] = 'Facebook';
$contactmethods['linkedin'] = 'LinkedIn';
return $contactmethods;
}
If you wanted to add a phone number to that you could just add something like
$contactmethods['phonenumber'] = 'Phone Number;
to the function above and it will create the field for you.