user2170133 user2170133 - 1 year ago 85
PHP Question

Add section and control to WordPress Customizer

I am trying to learn how to add new sections and control to WordPress Customizer. I watched a video about how to do it and copied exactly the author's code(adding color picker) but it did not work for me.
So, I have two files in the root of my child theme: customizer.php and functions.php.

In functions.php I require the customizer.php as follows:

function my_enqueue_assets() {
require get_stylesheet_directory() . '/customizer.php';}
add_action( 'wp_enqueue_scripts', 'my_enqueue_assets' );

And in customizer.php I have the following code:

function wcmcr_add_colour_picker( $wp_customize ) {
'default' => '#000',
'capability' => 'manage_options',
'transport' => 'postMessage',
'priority' => 10
'title' => 'Colour Options',
'description' => 'Colour Options for WCMCR',
'capability' => 'manage_options',
'priority' => '10',
'panel' => 'wcmcr_panel'
new WP_Customize_Color_Control(
'lable' => 'Title Color',
'section' => 'wcmcr_section_colour',
'settings' => 'wcmcr_title_colour'
if ( is_admin() ) {
add_action( 'customize_register', 'wcmcr_add_colour_picker' );

Nothing changes in Customizer settings.

Answer Source

I solved the issue by creating a panel with wcmcr_panel id.

$wp_customize->add_panel( __('wcmcr_panel'), array(
            'priority'       => 1,
            'capability'     => 'edit_theme_options',
            'theme_supports' => '',
            'title'          => __('Child Theme Settings', 'mytheme'),
            'description'    => __('Child Theme settings', 'mytheme'),
) );

The problem was that I referred to the panel in the section but that panel actually did not exist. Hence the section, setting and control could not be created.

Thanks for your help, I appreciate that.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download