The personal_options WordPress PHP action fires at the end of the ‘Personal Options’ settings table on the user editing screen.
Usage
add_action('personal_options', 'your_custom_function_name'); function your_custom_function_name($profile_user) { // your custom code here }
Parameters
$profile_user
(WP_User): The current WP_User object.
More information
See WordPress Developer Resources: personal_options
Examples
Add a custom field to the Personal Options
Add a custom field “Favorite Color” to the Personal Options section.
add_action('personal_options', 'add_favorite_color_field'); function add_favorite_color_field($profile_user) { // Get the user's favorite color $favorite_color = get_user_meta($profile_user->ID, 'favorite_color', true); ?> <tr> <th><label for="favorite_color"><?php _e('Favorite Color', 'textdomain'); ?></label></th> <td> <input type="text" name="favorite_color" id="favorite_color" value="<?php echo esc_attr($favorite_color); ?>" class="regular-text" /> </td> </tr> <?php }
Add a custom checkbox to the Personal Options
Add a custom checkbox “Enable Dark Mode” to the Personal Options section.
add_action('personal_options', 'add_dark_mode_checkbox'); function add_dark_mode_checkbox($profile_user) { // Get the user's dark mode preference $enable_dark_mode = get_user_meta($profile_user->ID, 'enable_dark_mode', true); ?> <tr> <th><?php _e('Dark Mode', 'textdomain'); ?></th> <td> <label for="enable_dark_mode"> <input type="checkbox" name="enable_dark_mode" id="enable_dark_mode" value="1" <?php checked($enable_dark_mode, 1); ?> /> <?php _e('Enable Dark Mode', 'textdomain'); ?> </label> </td> </tr> <?php }
Add a custom dropdown to the Personal Options
Add a custom dropdown “Preferred Language” to the Personal Options section.
add_action('personal_options', 'add_preferred_language_dropdown'); function add_preferred_language_dropdown($profile_user) { // Get the user's preferred language $preferred_language = get_user_meta($profile_user->ID, 'preferred_language', true); ?> <tr> <th><label for="preferred_language"><?php _e('Preferred Language', 'textdomain'); ?></label></th> <td> <select name="preferred_language" id="preferred_language"> <option value="en" <?php selected($preferred_language, 'en'); ?>><?php _e('English', 'textdomain'); ?></option> <option value="es" <?php selected($preferred_language, 'es'); ?>><?php _e('Spanish', 'textdomain'); ?></option> <option value="fr" <?php selected($preferred_language, 'fr'); ?>><?php _e('French', 'textdomain'); ?></option> </select> </td> </tr> <?php }
Add a custom date picker to the Personal Options
Add a custom date picker “Date of Birth” to the Personal Options section.
add_action('personal_options', 'add_date_of_birth_picker'); function add_date_of_birth_picker($profile_user) { // Get the user's date of birth $date_of_birth = get_user_meta($profile_user->ID, 'date_of_birth', true); ?> <tr> <th><label for="date_of_birth"><?php _e('Date of Birth', 'textdomain'); ?></label></th> <td> <input type="date" name="date_of_birth" id="date_of_birth" value="<?php echo esc_attr($date_of_birth); ?>" class="regular-text" /> </td> </tr> <?php }