X

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.



Code Snippet:


<?
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">
<tr>
<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>
</td>
</tr>
</table>
<? }

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'] );
}
?>

Comments  Leave a Reply

  1. Hey Kevin please let me know how can we add listbox and radio type input in the above snippet and how can we make certain fields required

    1.  Hi Amit, you only need to ask the question once I try and get to everything as fast as I can. I will add a snippet next week that will address this question about adding select and radio / checkboxes to the user profile section.

      1. thanks Kevin

  2. How can we add a Listbox and Radio type of fields in the above snippets and how can we make the certain fields required. Thanks in advance

  3. How can we add a Listbox and Radio type of fields in the above snippets and how can we make the certain fields required. Thanks in advance

  4. This code does’nt seem to work in 3.3.1, any ideas …

    1. Got the error, it is just the the php tag error on line 14 it should be <?php

      1. thanks a lot for these snippets, it is really helpful

        1.  Hi Amit, glad to see you got things working properly. Enjoy the snippets.

  5. Brilliant! Your site has saved me hours of head scratching.
    Thanks.

    1. No problem, glad I could help.

  6. Tweets that mention Wordpress Add & display custom profile info – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com January 16, 2011 at 11:20 pm

    […] This post was mentioned on Twitter by wp_freak, WPSNIPP. WPSNIPP said: #wordpress Add & display custom profile info http://bit.ly/hTg1GX #blog please RT 🙂 […]

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!