USharing
开放博客

WordPress Custom Fields User Profile Page

WordPress Add Custom Fields User Edit Profile Page – In this post we see how we can add custom fields to user profile edit page in WordPress at admin end. When admin wants to add some extra information for the users in his/her site, then custom fields can play important role.

As we know, WordPress provides hooks for almost every other feature/functionality so that we can update or manipulate according to our need. So for this also we’ll use some hooks to fulfill our post purpose.

Let’s start with the code –

<?php
 
/**
*  @param $user
*  @author Webkul
*/
 
add_action( 'edit_user_profile', 'wk_custom_user_profile_fields' );
 
function wk_custom_user_profile_fields( $user )
{
    echo '<h3 class="heading">Custom Fields</h3>';
    
    ?>
    
    <table class="form-table">
  <tr>
            <th><label for="contact">Contact</label></th>
 
      <td><input type="text" class="input-text form-control" name="contact" id="contact" />
            </td>
 
  </tr>
    </table>
    
    <?php
}
 
?>

In above code, we add action to hook ‘edit_user_profile’ and create one input field in callback function. This function will display field when you are editing other user profile. If you want to show created fields for all profiles then use ‘show_user_profile’ hook and add action for same callback function.

<?php
add_action( 'show_user_profile', 'wk_custom_user_profile_fields' );
?>

After executing above code, custom field will display on user profile edit page as below –

Now, to save the data for created custom fields we’ll use ‘edit_user_profile_update’ hook.

赞(0) 打赏
未经允许不得转载:USharing » WordPress Custom Fields User Profile Page

觉得文章有用就打赏一下文章作者

微信扫一扫打赏