skip to Main Content

Search WordPress Code Snippets – Quick Solutions for Developers


How to Add Custom Fields to User Profiles in WordPress Admin

Add a custom field to user profiles in the admin area.

add_action('show_user_profile', 'codebykp_add_custom_user_profile_fields');
add_action('edit_user_profile', 'codebykp_add_custom_user_profile_fields');
function codebykp_add_custom_user_profile_fields($user) {
    ?>
    <h3>Extra Profile Information</h3>
    <table class="form-table">
        <tr>
            <th><label for="custom_field">Custom Field</label></th>
            <td>
                <input type="text" name="custom_field" id="custom_field" value="<?php echo esc_attr(get_user_meta($user->ID, 'custom_field', true)); ?>" class="regular-text" />
            </td>
        </tr>
    </table>
    <?php
}

add_action('personal_options_update', 'codebykp_save_custom_user_profile_fields');
add_action('edit_user_profile_update', 'codebykp_save_custom_user_profile_fields');
function codebykp_save_custom_user_profile_fields($user_id) {
    update_user_meta($user_id, 'custom_field', sanitize_text_field($_POST['custom_field']));
}


I’m a WordPress developer with 10+ years of experience in WooCommerce and custom plugins. I combine technical expertise with design flair to help you create standout, user-friendly websites. Let’s transform your digital presence!

Back To Top