do_action( ‘add_option’, string $option, mixed $value )

Fires before an option is added.


Name of the option to add.
Value of the option.


do_action( 'add_option', $option, $value );



User Contributed Notes

  1. Skip to note 2 content

    For adding prefix to the option value
    we can consider below example

    // Define a custom function to be executed when the 'add_option' hook is triggered
    function wpdocs_custom_add_option_action( $option, $value ) {
        // Perform custom logic or modifications to the option or its value
        // For example, let's add a prefix to the option value
        $modified_value = 'prefix_' . $value;
        // Save the modified value back to the option
        update_option( $option, $modified_value );
    add_action( 'add_option', 'wpdocs_custom_add_option_action', 10, 2 );

You must log in before being able to contribute a note or feedback.