wordpress snippets last updated   : July 14, 2014
we now have 634 snippets

Add & display custom profile info

wordpress snippet

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.

snippet :  PHP - functions.phpcopy
<?
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'] );
}
?>
source →
  • Pingback: Tweets that mention Wordpress Add & display custom profile info – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com

  • Me

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

    • http://wpsnipp.com Kevin Chard

      No problem, glad I could help.

  • amit

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

    • amit

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

      • amit

        thanks a lot for these snippets, it is really helpful

        • http://wpsnipp.com Kevin Chard

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

  • amit

    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

  • amit shyamsukha

    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

  • amit shyamsukha

    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

    • http://wpsnipp.com Kevin Chard

       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.

      • amit shyamsukha

        thanks Kevin

jqsnipp.com | we just launched jquery snippets website