WP_Customize_Manager::add_control() WordPress Method

The add_control() method allows developers to programmatically add new controls to the Customizer. This is typically done in the Customizer init() method. Controls can be added to any Customizer panel, and will be displayed in the order they are added. Controls must be added to a Customizer panel before they will be displayed. To add a control to a panel, use the add_control() method. This method accepts two parameters: The first parameter is the ID of the control. This should be a unique ID, as it will be used by the Customizer to identify the control. The second parameter is an array of options for the control. These options include the control type, a label for the control, and any other options supported by the control type.

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

Adds a customize control.


Description

Top ↑

See also


Top ↑

Parameters

$id

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

$args

(array)(Optional) Array of properties for the new Control object. See WP_Customize_Control::__construct() for information on accepted arguments.

Default value: array()


Top ↑

Return

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


Top ↑

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
VersionDescription
4.5.0Return added WP_Customize_Control instance.
3.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More