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.
将customrizer.php文件直接包含到functions.php文件中。
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.