X

Add & Display Custom Profile Info

Snippets by IsItWP

Do you want to add a new “address” field to user profile? While there’s probably a plugin for this, we have created a quick code snippet that you can use to add and display custom profile info in WordPress.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

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

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 19 best WordPress plugins for non-profits and how to set up Google analytics eCommerce tracking for WooCommerce.

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!