Ask any question about WordPress here... and get an instant response.
Post this Question & Answer:
How can I add custom fields to a WordPress user profile? Pending Review
Asked on Apr 13, 2026
Answer
To add custom fields to a WordPress user profile, you can use the `show_user_profile` and `edit_user_profile` hooks to display the fields, and the `personal_options_update` and `edit_user_profile_update` hooks to save the data. This allows you to extend user profiles with additional information.
<!-- BEGIN COPY / PASTE -->
// Add custom fields to user profile
function my_custom_user_profile_fields($user) {
?>
<h3>Extra Profile Information</h3>
<table class="form-table">
<tr>
<th><label for="twitter">Twitter</label></th>
<td>
<input type="text" name="twitter" id="twitter" value="<?php echo esc_attr(get_the_author_meta('twitter', $user->ID)); ?>" class="regular-text" /><br />
<span class="description">Please enter your Twitter username.</span>
</td>
</tr>
</table>
<?php
}
add_action('show_user_profile', 'my_custom_user_profile_fields');
add_action('edit_user_profile', 'my_custom_user_profile_fields');
// Save custom fields
function my_save_custom_user_profile_fields($user_id) {
if (!current_user_can('edit_user', $user_id)) {
return false;
}
update_user_meta($user_id, 'twitter', $_POST['twitter']);
}
add_action('personal_options_update', 'my_save_custom_user_profile_fields');
add_action('edit_user_profile_update', 'my_save_custom_user_profile_fields');
<!-- END COPY / PASTE -->Additional Comment:
- Ensure you have the necessary permissions to edit user profiles by checking user capabilities.
- Use `esc_attr()` for outputting data to prevent XSS vulnerabilities.
- Consider using a plugin like Advanced Custom Fields for a more user-friendly interface.
Recommended Links:
