g72jfg
Last Updated: February 25, 2016
·
6.402K
· betoarpi
Rob

Adding a Phone Numer Field to Wordpress User Profile

1.- Open your funtions.php file and scroll down
2.- Paste the following code in:

add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) { ?>
<h3>Extra profile information</h3>
    <table class="form-table">
<tr>
            <th><label for="phone">Phone Number</label></th>
            <td>
            <input type="text" name="phone" id="phone" value="<?php echo esc_attr( get_the_author_meta( 'phone', $user->ID ) ); ?>" class="regular-text" /><br />
                <span class="description">Please enter your phone number.</span>
            </td>
</tr>
</table>
<?php }

The code above will create the custom field in the user profile page

3.- Add this extra function to make wordpress save your new field information:

add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );

function my_save_extra_profile_fields( $user_id ) {

if ( !current_user_can( 'edit_user', $user_id ) )
    return false;

update_usermeta( $user_id, 'phone', $_POST['phone'] );
}

4.- Now you can display your user phone numer wherever you want. Here's an exmple:

<strong>Phone Number:</strong> <?php the_author_meta( 'phone' ); ?></p>

If you want to show any other information just change phone per your new field name and enjoy it!

Say Thanks
Respond

1 Response
Add your response

14637
Vxtu9b2j normal

Thanks,

This worked a treat!

over 1 year ago ·