Home » Hooks » edit_user_profile

The edit_user_profile hook is a WordPress action hook that is triggered when a user edits their profile in the WordPress dashboard. This hook allows developers to add custom fields or content to the user profile page.

The edit_user_profile hook is used in conjunction with the show_user_profile hook, which is triggered when a user views their own profile in the dashboard. Together, these hooks allow developers to add custom fields or content to both the view and edit modes of the user profile page.

This hook provides a great way to add additional functionality to the user profile page, such as custom fields for social media links or additional contact information.

Example Usage Code:

function add_custom_user_profile_fields( $user ) {
    <h3><?php _e('Custom User Profile Fields'); ?></h3>

    <table class="form-table">
            <th><label for="twitter">Twitter</label></th>
                <input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_user_meta( $user->ID, 'twitter', true ) ); ?>" class="regular-text" /><br />
                <span class="description"><?php _e('Please enter your Twitter username.'); ?></span>
add_action( 'edit_user_profile', 'add_custom_user_profile_fields' );

In this example, we add a custom field for a user’s Twitter username to their profile page. The add_custom_user_profile_fields function is hooked to the edit_user_profile action, which displays the custom field on the page. When the user updates their profile, the value of the custom field is saved as user meta data and can be retrieved and displayed later.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.