Add Section and Control to WordPress Customizer

advertisements

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 ) {
        $wp_customize->add_setting(
            'wcmcr_title_colour',
            array(
                'default'   => '#000',
                'capability'    => 'manage_options',
                'transport'     => 'postMessage',
                'priority'  => 10
                )
            );
        $wp_customize->add_section(
            'wcmcr_section_colour',
            array(
                'title'     => 'Colour Options',
                'description'   => 'Colour Options for WCMCR',
                'capability'    => 'manage_options',
                'priority'  => '10',
                'panel'     => 'wcmcr_panel'
                )
            );
        $wp_customize->add_control(
            new WP_Customize_Color_Control(
                $wp_customize,
                'wcmcr_title_colour',
                array(
                    '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.


Include the customizer.php file directly to the functions.php file.