Like Us Like Us Facebook Subscribe Subscribe us YouTube Whatsapp Share us Whatsapp Query Send your queries

How to add a field on the WordPress Users profile

How to add a field on the WordPress Users profile

If you want to add an extra field on WordPress User profile, then we can do it using plugins or adding some code in “functions.php” . In this tutorial I using the second method. Each and every WordPress theme has a file called functions.php , we have to just open this file and paste the code given below

Code given below will create some extra field like contact, gender

//extra fields
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>Contact No.</h3>
<table class="form-table">
<th><label for="twitter">Contact</label></th>
<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 Contact No.</span>
<th><label for="twitter">Gender</label></th>
<select name="gender" id="gender" class="regular-text">
<option value="<?php echo esc_attr( get_the_author_meta( 'gender', $user->ID ) ); ?>"><?php echo esc_attr( get_the_author_meta( 'gender', $user->ID ) ); ?></option>
<option value="Male">Male</option>
<option value="Female">Female</option>
<span class="description">Please Select your Gender</span>

<?php }

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_user_meta( $user_id, 'contact', $_POST['contact'] );
update_user_meta( $user_id, 'gender', $_POST['gender'] );

Screen shot for How to add a field on the WordPress Users profile

Now go to your profile page You will able to see contact and gender field.

5 1 vote
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments