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

Adds a customize control.

Description

See also

Parameters

$idWP_Customize_Control|stringrequired
Customize Control object, or ID.
$argsarrayoptional
Array of properties for the new Control object.
See WP_Customize_Control::__construct() for information on accepted arguments.

Default:array()

Return

WP_Customize_Control The instance of the control that was added.

Source

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;
}

Changelog

VersionDescription
4.5.0Return added WP_Customize_Control instance.
3.4.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    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.