Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use profile_personal_options action in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
September 14, 2022
5 minutes read

Hey there! Let’s dive into the `profile_personal_options` action hook. This hook fires only when a user is editing their own profile. To use this hook, you need to register it with `add_action`. You can place this code in the `functions.php` file of your activated theme or create a custom WordPress Plugin. At WePlugins, we always recommend creating a custom plugin to ensure nothing breaks when you update your theme.

In the examples below, we’ll define a function `weplugins_execute_on_profile_personal_options_event` which takes one parameter and is registered using `add_action`. The first parameter is the hook name, the second is the function name, the third is the priority, and the last is the number of arguments to be passed.

Sometimes, you might need to remove a registered hook, and for that, you can use `remove_action`.

Parameters

    Below is the required parameter for using this hook:

  • $profile_user: (WP_User) The current WP_User object.

Live Example 1

This example shows how to add a custom field below the color scheme and above the username field:

// This will show below the color scheme and above the username field
add_action( 'profile_personal_options', 'weplugins_extra_profile_fields' );
function weplugins_extra_profile_fields( $user ) {
    // get the value of a single meta key
    $meta_value = get_user_meta( $user->ID, 'meta_key', true ); // $user contains WP_User object
    // do something with it.
    ?>
    <input type="text" name="value" value="<?php echo esc_attr( $meta_value ); ?>" />
    <?php
}
&#91;/php&#93;

<h2>Live Example 2</h2>
<p>Below is an example of how you can use this hook to execute custom functionality:</p>

function weplugins_execute_on_profile_personal_options_event($profile_user){
    // Code to be executed when this action occurs in WordPress.
    // Use the parameters received in the function arguments & implement the required additional custom functionality according to your website requirements.
}
// add the action
add_action( "profile_personal_options", "weplugins_execute_on_profile_personal_options_event" , 10, 1);

Live Example 3

To remove a hook callback, use the example below:

remove_action( "profile_personal_options", "weplugins_execute_on_profile_personal_options_event", 10, 1 );

Please make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.

Access Premium WordPress Plugins

Contact Us

If you need any customization or have trouble using this hook, please contact us. We’d be happy to assist you!

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.