Title: add_option
Published: April 25, 2014
Last modified: August 20, 2026

---

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

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/add_option/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/add_option/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/add_option/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/add_option/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/add_option/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/add_option/?output_format=md#wp--skip-link--target)

Fires before an option is added.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/add_option/?output_format=md#parameters)󠁿

 `$option`string

Name of the option to add.

`$value`mixed

Value of the option.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/add_option/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/option.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/option.php#L1140)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/option.php#L1140-L1140)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/add_option/?output_format=md#related)󠁿

| Used by | Description | 
| [add_option()](https://developer.wordpress.org/reference/functions/add_option/)`wp-includes/option.php` |

Adds a new option.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/add_option/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/add_option/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/add_option/?output_format=md#comment-content-6564)
 2.   [IT Path Solutions](https://profiles.wordpress.org/itpathsolutions/)  [  3 years ago  ](https://developer.wordpress.org/reference/hooks/add_option/#comment-6564)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadd_option%2F%23comment-6564)
    Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadd_option%2F%23comment-6564)
 4. For adding prefix to the option value
     we can consider below example
 5.     ```php
        // 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 );
        ```
    
 6.  * Remember to limit to a specific option name, as using this example directly 
       will break your WordPress install.
     * [crstauf](https://profiles.wordpress.org/crstauf/) [3 years ago](https://developer.wordpress.org/reference/hooks/add_option/#comment-6568)
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadd_option%2F%3Freplytocom%3D6564%23feedback-editor-6564)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadd_option%2F)
before being able to contribute a note or feedback.