The profile_personal_options WordPress action fires after the ‘Personal Options’ settings table on the ‘Profile’ editing screen, and only if the current user is editing their own profile.
Usage
add_action('profile_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: profile_personal_options
Examples
Add a custom field to the personal options
This example adds a custom field for the user’s favorite color to the personal options section.
add_action('profile_personal_options', 'add_favorite_color_field');
function add_favorite_color_field($profile_user) {
$favorite_color = get_user_meta($profile_user->ID, 'favorite_color', true);
?>
<tr>
<th scope="row">Favorite Color</th>
<td>
<input type="text" name="favorite_color" id="favorite_color" value="<?php echo esc_attr($favorite_color); ?>" />
</td>
</tr>
<?php
}
Save custom field data
This example saves the custom field data when the profile is updated.
add_action('personal_options_update', 'save_favorite_color_field');
function save_favorite_color_field($user_id) {
if (current_user_can('edit_user', $user_id)) {
update_user_meta($user_id, 'favorite_color', sanitize_text_field($_POST['favorite_color']));
}
}
Add a custom message after the personal options
This example adds a custom message after the personal options section.
add_action('profile_personal_options', 'add_custom_message');
function add_custom_message($profile_user) {
echo '<p>Your custom message goes here.</p>';
}
Add custom CSS to style the personal options
This example adds custom CSS to style the personal options section.
add_action('admin_head-profile.php', 'add_custom_css');
function add_custom_css() {
echo '<style>
/* Your custom CSS here */
</style>';
}
Add a custom JavaScript to the personal options
This example adds custom JavaScript to the personal options section.
add_action('admin_footer-profile.php', 'add_custom_js');
function add_custom_js() {
echo '<script>
// Your custom JavaScript here
</script>';
}