Title: WP_Customize_Manager::add_setting
Published: April 25, 2014
Last modified: February 24, 2026

---

# WP_Customize_Manager::add_setting( WP_Customize_Setting|string $id, array $args = array() ): 󠀁[WP_Customize_Setting](https://developer.wordpress.org/reference/classes/wp_customize_setting/)󠁿

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting/?output_format=md#user-contributed-notes)

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

Adds a customize setting.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting/?output_format=md#description)󠁿

### 󠀁[See also](https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting/?output_format=md#see-also)󠁿

 * [WP_Customize_Setting::__construct()](https://developer.wordpress.org/reference/classes/WP_Customize_Setting/__construct/)

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

 `$id`[WP_Customize_Setting](https://developer.wordpress.org/reference/classes/wp_customize_setting/)
|stringrequired

Customize Setting object, or ID.

`$args`arrayoptional

Array of properties for the new Setting object.
 See [WP_Customize_Setting::__construct()](https://developer.wordpress.org/reference/classes/wp_customize_setting/__construct/)
for information on accepted arguments.

Default:`array()`

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting/?output_format=md#return)󠁿

 [WP_Customize_Setting](https://developer.wordpress.org/reference/classes/wp_customize_setting/)
The instance of the setting that was added.

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

    ```php
    public function add_setting( $id, $args = array() ) {
    	if ( $id instanceof WP_Customize_Setting ) {
    		$setting = $id;
    	} else {
    		$class = 'WP_Customize_Setting';

    		/** This filter is documented in wp-includes/class-wp-customize-manager.php */
    		$args = apply_filters( 'customize_dynamic_setting_args', $args, $id );

    		/** This filter is documented in wp-includes/class-wp-customize-manager.php */
    		$class = apply_filters( 'customize_dynamic_setting_class', $class, $id, $args );

    		$setting = new $class( $this, $id, $args );
    	}

    	$this->settings[ $setting->id ] = $setting;
    	return $setting;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-manager.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-customize-manager.php#L3780)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-customize-manager.php#L3780-L3797)

## 󠀁[Hooks](https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting/?output_format=md#hooks)󠁿

 [apply_filters( ‘customize_dynamic_setting_args’, false|array $setting_args, string $setting_id )](https://developer.wordpress.org/reference/hooks/customize_dynamic_setting_args/)

Filters a dynamic setting’s constructor args.

 [apply_filters( ‘customize_dynamic_setting_class’, string $setting_class, string $setting_id, array $setting_args )](https://developer.wordpress.org/reference/hooks/customize_dynamic_setting_class/)

Allow non-statically created settings to be constructed with custom [WP_Customize_Setting](https://developer.wordpress.org/reference/classes/wp_customize_setting/)
subclass.

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

| Uses | Description | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

| Used by | Description | 
| [WP_Customize_Manager::add_dynamic_settings()](https://developer.wordpress.org/reference/classes/wp_customize_manager/add_dynamic_settings/)`wp-includes/class-wp-customize-manager.php` |

Registers any dynamically-created settings, such as those from $_POST[‘customized’] that have no corresponding setting created.

  | 
| [WP_Customize_Manager::register_controls()](https://developer.wordpress.org/reference/classes/wp_customize_manager/register_controls/)`wp-includes/class-wp-customize-manager.php` |

Registers some default controls.

  |

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

| Version | Description | 
| [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | Return added [WP_Customize_Setting](https://developer.wordpress.org/reference/classes/wp_customize_setting/) instance. | 
| [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. |

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

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting/?output_format=md#comment-content-3026)
 2.    [Marc Wiest](https://profiles.wordpress.org/marclarr/)  [  7 years ago  ](https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting/#comment-3026)
 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%2Fclasses%2Fwp_customize_manager%2Fadd_setting%2F%23comment-3026)
     Vote results for this note: 1[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%2Fclasses%2Fwp_customize_manager%2Fadd_setting%2F%23comment-3026)
 4.  The `**sanitize_callback**` parameter needs to refer to a function that accepts
     at least two parameters or a [variable argument length](http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list).
     The two parameters send to the callback are 1.) the value of the setting and 2.)
     the instance of [WP_Customize_Setting](https://developer.wordpress.org/reference/classes/wp_customize_setting/).
     Using a callback that only accepts one parameter may result in a customize validation
     failiure upon saving or a PHP warning (see error log).
 5.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_customize_manager%2Fadd_setting%2F%3Freplytocom%3D3026%23feedback-editor-3026)
 6.   [Skip to note 4 content](https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting/?output_format=md#comment-content-5797)
 7.    [Abdallah Youssef](https://profiles.wordpress.org/abdallahussef/)  [  4 years ago  ](https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting/#comment-5797)
 8.  [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%2Fclasses%2Fwp_customize_manager%2Fadd_setting%2F%23comment-5797)
     Vote results for this note: -1[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%2Fclasses%2Fwp_customize_manager%2Fadd_setting%2F%23comment-5797)
 9.      ```php
         $wp_customize->add_setting( 'wpdocs_setting_id', array(
           'type' => 'theme_mod', // or 'option'
           'capability' => 'edit_theme_options',
           'theme_supports' => '', // Rarely needed.
           'default' => '',
           'transport' => 'refresh', // or postMessage
           'sanitize_callback' => '',
           'sanitize_js_callback' => '', // Basically to_json.
         ) );
         ```
     
 10.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_customize_manager%2Fadd_setting%2F%3Freplytocom%3D5797%23feedback-editor-5797)

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