-
Notifications
You must be signed in to change notification settings - Fork 327
Fields
Aristeides Stathopoulos edited this page May 23, 2015
·
17 revisions
The WordPress Customizer API allows you to add a new control like this:
function my_custom_text_settings( $wp_customize ) {
// Register the settings
$wp_customize->add_setting( 'my_setting', array(
'default' => 'some-default-value',
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
) );
$wp_customize->add_setting( 'my_setting_2', array(
'default' => 'some-default-value',
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
) );
// Add the controls
$wp_customize->add_control( 'my_setting', array(
'label' => __( 'My custom control', 'translation_domain' ),
'section' => 'my_section',
'settings' => 'my_setting',
'type' => 'text',
'priority' => 10
) );
$wp_customize->add_control( 'my_setting_2', array(
'label' => __( 'My custom control 2', 'translation_domain' ),
'section' => 'my_section',
'settings' => 'my_setting_2',
'type' => 'text',
'priority' => 20
) );
}
add_action( 'customize_register', 'my_custom_text_settings' );
You can do the exact same thing using Kirki like this:
Kirki::add_config( 'my_config', array(
'options_type' => 'theme_mod',
'capability' => 'edit_theme_options',
) );
Kirki::add_field( 'my_config', array(
'settings' => 'my_setting',
'label' => __( 'My custom control', 'translation_domain' ),
'section' => 'my_section',
'type' => 'text',
'priority' => 10,
'default' => 'some-default-value',
) );
Kirki::add_field( 'my_config', array(
'settings' => 'my_setting_2',
'label' => __( 'My custom control 2', 'translation_domain' ),
'section' => 'my_section',
'type' => 'text',
'priority' => 20,
'default' => 'some-default-value',
) );
WordPress core allows you to add a lot of fields in your customizer. This way you can add options to your theme without using an options framework like you needed a few years ago.
We recommend you read this blog post from Otto to learn the basics of how to use the WordPress customizer. and the Handbook on WordPress.org.
The documentation for Kirki has changed! You can now find the new docs inside the "docs" folder of the plugin here: https://github.com/aristath/kirki/tree/develop/docs.