Introduction to the new and powerful live-preview options system for Wordpress
by Steffen Gammelgaard Brand Rocket
- PAUL UNDERWOOD
Now the only theme options system approved by wordpress.org
Easier with one standard instead of hundreds of different options systems to master
1
3
2
Live preview makes it a much easier to customise a theme and get the options right the first time
4.3
from
version
Why learn the Customiser system?
Because it has
customiser.php
All the settings
customiser.js
The live preview
1
2
Get the option
3
$wp_customize->add_section( 'custom_section', array(
'title' => __( 'Section', 'theme-name' ),
'description' => __( 'Add multiple settings here...' ),
) );
$wp_customize->add_setting( 'brandrocket_logo', array(
'sanitize_callback' => 'esc_url_raw',
) );
$wp_customize->add_control( new WP_Customize_Image_Control(
$wp_customize, 'brandrocket_logo', array(
'label' => __( 'Logo', 'theme-name' ),
'section' => 'brandrocket_logo_section',
'settings' => 'brandrocket_logo',
) ) );
$wp_customize->add_setting( 'setting_id', array(
'type' => 'theme_mod', // or 'option'
) );
// Register the settings
$wp_customize->add_setting( 'my_setting', 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', 'theme-name' ),
'section' => 'my_section',
'settings' => 'my_setting',
'type' => 'text',
'priority' => 10
) );
Wordpress customiser API
Kirki
// Add the controls
$fields[] = array(
'label' => __( 'My custom control', 'theme-name' ),
'section' => 'my_section',
'settings' => 'my_setting',
'type' => 'text',
'priority' => 10,
'default' => 'some-default-value',
'option_type' => 'theme_mod',
'capability' => 'edit_theme_options',
);
- It can potentially replace a series of plugins
- A library of easy copy-paste customiser settings
- The enhanced UX will make WP even more popular
on the effects of the new customiser
Steffen Gammelgaard
Ressources
Wordpress Developers -> Customiser API
Smashing Magazines Developers guide
Old but still relevant introduction (Otto)
Colorscheme settings and controls
Adding more Customiser settings
Theme Customizer Boilerplate (slobodan)
Custom Customizer Controls (paulund)