WordPress.org

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Class Reference/WP Customize Control

This class is used with the Theme Customization API to render an input control on the Theme Customizer in WordPress 3.4 or newer.

Usage

$wp_customize->add_control(
    new WP_Customize_Control(
        $wp_customize,
        'your_setting_id',
        array(
            'label'          => __( 'Dark or light theme version?', 'theme_name' ),
            'section'        => 'your_section_id',
            'settings'       => 'your_setting_id',
            'type'           => 'radio',
            'choices'        => array(
                'dark'   => __( 'Dark' ),
                'light'  => __( 'Light' )
            )
        )
    )
);

Parameters

$manager
(WP_Customize_Manager) (required) Customizer bootstrap instance.
Default: None
$id
(string) (required) Control ID.
Default: None
$args
(array) (required) An associative array containing arguments for the setting.
Default: None

Arguments

settings
All settings tied to the control. If undefined, `$id` will be used.
setting
The primary setting for the control (if there is one).
priority
Order priority to load the control. Default 10.
section
Section the control belongs to. Default empty.
label
Label for the control. Default empty.
description
Description for the control. Default empty.
choices
List of choices for 'radio' or 'select' type controls, where values are the keys, and labels are the values. Default empty array.
input_attrs
List of custom input attributes for control output, where attribute names are the keys and values are the values. Not used for 'checkbox', 'radio', 'select', 'textarea', or 'dropdown-pages' control types. Default empty array.
type
Control type. Core controls include 'text', 'checkbox', 'textarea', 'radio', 'select', and 'dropdown-pages'. Additional input types such as 'email', 'url', 'number', 'hidden', and 'date' are supported implicitly. Default 'text'.

Input Types

With this class you can create the following input types:

  • text (default)
  • checkbox
  • radio (requires choices array in $args)
  • select (requires choices array in $args)
  • dropdown-pages
  • textarea (since WordPress 4.0)

Note: Since WordPress 4.0, input types such as 'email', 'url', 'number', 'hidden' and 'date' are supported implicitly as variations of the 'text' input type.


See also index of Class Reference and index of Function Reference.