Add & display custom profile info

Adding the first block of code to the functions.php of your wordpress theme will add a new field “address” to the user profile. You can get and display this field using get_the_author_meta() and would display it within the page like so echo $auth->address. You can create new fields by duplicating the code in the example.



add_action( 'show_user_profile', 'extra_user_profile_fields' );
add_action( 'edit_user_profile', 'extra_user_profile_fields' );
function extra_user_profile_fields( $user ) { ?>
<h3><?php _e("Mailing details", "blank"); ?></h3>
<table class="form-table">
<th><label for="address"><?php _e("Address"); ?></label></th>
<td><input type="text" name="address" id="address" value="<?php echo esc_attr( get_the_author_meta( 'address', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Please type address here."); ?></span>
<? }
add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
function save_extra_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
update_usermeta( $user_id, 'address', $_POST['address'] );

Leave a comment