add custom fields to user profile wordpress without plugin

WordPress tutorial, add custom fields to user profile wordpress without plugin. For adding extra details use can use following sample code in functions.php file. You can modify the code as per your requirement.

add custom fields to user profile wordpress without plugin

add custom fields to user profile wordpress without plugin
add custom fields to user profile wordpress without plugin

Note: If you are not wordpress developer then you should ask any wordpress developer to do this changes.

add_action( 'show_user_profile', 'extra_fields_to_user' );
add_action( 'edit_user_profile', 'extra_fields_to_user' );

function extra_fields_to_user( $user ) { ?>

 <h3>Extra profile information</h3>

 <table>

 <tr>
 <th><label for="facebook">facebook</label></th>

 <td>
 <input type="text" name="facebook" id="facebook" value="<?php echo esc_attr( get_the_author_meta( 'facebook', $user->ID ) ); ?>" /><br />
 <span>Please enter your facebook username.</span>
 </td>
 </tr>

 </table>
<?php }
add_action( 'personal_options_update', 'extra_fields_to_user_save' );
add_action( 'edit_user_profile_update', 'extra_fields_to_user_save' );

function extra_fields_to_user_save( $user_id ) {

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

 /* Copy and paste this line for additional fields. Make sure to change 'facebook' to the field ID. */
 update_usermeta( $user_id, 'facebook', $_POST['facebook'] );
}

showing the user information use following code.
<?php the_author_meta( ‘facebook’ ); ?>

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

One thought on “add custom fields to user profile wordpress without plugin”

Leave a Reply

Your email address will not be published.