WP_Customize_Manager::add_control( WP_Customize_Control|string $id, array $args = array() )

Add a customize control.

Description Description

Parameters Parameters


(WP_Customize_Control|string) (Required) Customize Control object, or ID.


(array) (Optional) Array of properties for the new Control object.

  • 'settings'
    (array) All settings tied to the control. If undefined, defaults to $setting. IDs in the array correspond to the ID of a registered WP_Customize_Setting.
  • 'setting'
    (string) The primary setting for the control (if there is one). Default is 'default'.
  • 'capability'
    (string) Capability required to use this control. Normally derived from $settings.
  • 'priority'
    (int) Order priority to load the control. Default 10.
  • 'section'
    (string) The section this control belongs to.
  • 'label'
    (string) Label for the control.
  • 'description'
    (string) Description for the control.
  • 'choices'
    (array) List of choices for 'radio' or 'select' type controls, where values are the keys, and labels are the values.
  • 'input_attrs'
    (array) List of custom input attributes for control output, where attribute names are the keys and values are the values.
  • 'allow_addition'
    (bool) Show UI for adding new content, currently only used for the dropdown-pages control. Default false.
  • 'type'
    (string) The type of the control. Default 'text'.
  • 'active_callback'
    (callback) Active callback.

Default value: array()

Top ↑

Return Return

(WP_Customize_Control) The instance of the control that was added.

Top ↑

Source Source

File: wp-includes/class-wp-customize-manager.php

	public function add_control( $id, $args = array() ) {
		if ( $id instanceof WP_Customize_Control ) {
			$control = $id;
		} else {
			$control = new WP_Customize_Control( $this, $id, $args );

		$this->controls[ $control->id ] = $control;
		return $control;

Top ↑

Changelog Changelog

Version Description
4.5.0 Return added WP_Customize_Control instance.
3.4.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Marcio Zebedeu

    basic use

    function register_customize_sections( $wp_customize ) {
        $wp_customize->add_section( 'example', array(
           'title'=> __( 'Add Your Name', 'TextDomain' ),
           'priority' => 201
        ) );
        $wp_customize->add_setting( 'setting' );
        $wp_customize->add_control( 'setting', array(
            'id'=> 'id',
            'label' => __( 'First Name:', 'TextDomain' ),
            'section' => 'example'
        ) );

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