定制器颜色控制不起作用

时间:2021-01-04 作者:sahan

我目前正在开发一个主题,该主题在Customizer中提供了更多定制。我正在尝试添加颜色控制选项,但它不起作用。这是我的密码。

/* Color Section */
    
    $wp_customize -> add_setting( \'navbar_color\', array(
        \'default\' => \'#45ace0\',
    ) );

    $wp_customize -> add_control( new WP_Customize_Color_Control( $wp_customize, \'navbar_color\', array(
            \'label\'     => __( \'Navbar Color\', \'text_domain\' ),
            \'section\'   => \'color_section\',
            \'settings\'  => \'navbar_color\',
        )
        
    ) );
    
    $wp_customize -> add_section( \'color_section\', array(
        \'title\'     => __( \'Color Section\', \'text_domain\' ),
    ) );
我看不出这里有什么问题。如果没有此自定义程序,则无法正常工作。但当我添加这段代码时,customizer并没有在加载时出现任何PHP错误。此外,当我将WP\\u Customize\\u Color\\u Control替换为WP\\u Customize\\u Image\\u Control时,它可以正常工作。此问题仅在颜色控制时发生。

此外,我在控制台中收到以下JS错误。

enter image description here

任何解决方案都将不胜感激。

3 个回复
最合适的回答,由SO网友:sahan 整理而成

终于找到了原因。原因是我将JQuery排入了选项页面的队列。当我删除JQuery排队时,一切都正常。感谢所有回复。

SO网友:Álvaro García

尝试将您的ID名称更改为其他名称。可能已经在使用ID:

navbar_color
收件人:

my_navbar_color

SO网友:HK89

根据您的需要:

注册自定义设置,在函数中添加以下代码。php

function themename_customize_register($wp_customize){

$wp_customize->add_section(\'themename_color_scheme\', array(
    \'title\'    => __(\'Color Scheme\', \'themename\'),
    \'priority\' => 120,
));

//  =============================
//  = Color Picker              =
//  =============================

$wp_customize->add_setting(\'themename_theme_options[navbar_color]\', array(
    \'default\'           => \'#000\',
    \'sanitize_callback\' => \'sanitize_hex_color\',
    \'capability\'        => \'edit_theme_options\',
    \'type\'           => \'option\',

));

$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, \'navbar_color\', array(
    \'label\'    => __(\'Link Color\', \'themename\'),
    \'section\'  => \'themename_color_scheme\',
    \'settings\' => \'themename_theme_options[navbar_color]\',
)));


//  =============================
//  = Text Input                =
//  =============================
$wp_customize->add_setting(\'themename_theme_options[text_test]\', array(
    \'default\'        => \'Custom Text!\',
    \'capability\'     => \'edit_theme_options\',
    \'type\'           => \'option\',

));

$wp_customize->add_control(\'themename_text_test\', array(
    \'label\'      => __(\'Text Test\', \'themename\'),
    \'section\'    => \'themename_color_scheme\',
    \'settings\'   => \'themename_theme_options[text_test]\',
));

//  =============================
//  = Image Upload              =
//  =============================
$wp_customize->add_setting(\'themename_theme_options[image_upload_test]\', array(
    \'default\'           => \'image.jpg\',
    \'capability\'        => \'edit_theme_options\',
    \'type\'           => \'option\',

));

$wp_customize->add_control( new WP_Customize_Image_Control($wp_customize, \'image_upload_test\', array(
    \'label\'    => __(\'Image Upload Test\', \'themename\'),
    \'section\'  => \'themename_color_scheme\',
    \'settings\' => \'themename_theme_options[image_upload_test]\',
)));

//  =============================
//  = File Upload               =
//  =============================
$wp_customize->add_setting(\'themename_theme_options[upload_test]\', array(
    \'default\'           => \'arse\',
    \'capability\'        => \'edit_theme_options\',
    \'type\'           => \'option\',

));

$wp_customize->add_control( new WP_Customize_Upload_Control($wp_customize, \'upload_test\', array(
    \'label\'    => __(\'Upload Test\', \'themename\'),
    \'section\'  => \'themename_color_scheme\',
    \'settings\' => \'themename_theme_options[upload_test]\',
)));

 }

add_action(\'customize_register\', \'themename_customize_register\');
参考链接了解您的知识Click

enter image description here

相关推荐