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
See also
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()
Return
(WP_Customize_Control) The instance of the control that was added.
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; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
4.5.0 | Return added WP_Customize_Control instance. |
3.4.0 | Introduced. |