我想为Wordpress Customizer的颜色部分添加多个选项,这是我的代码(较低的代码(starter\\u new\\u setting\\u name2)覆盖较高的代码):
function starter_customize_register( $wp_customize )
{
$wp_customize->add_section( \'starter_new_section_name\' , array(
\'title\' => __( \'Visible Section Name\'),
\'priority\' => 30
) );
$wp_customize->add_setting( \'starter_new_setting_name\' , array(
\'default\' => \'#04A0c0\',
\'transport\' => \'refresh\',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, \'link_color\', array(
\'label\' => __( \'H1 Color\', \'starter\' ),
\'section\' => \'starter_new_section_name\',
\'settings\' => \'starter_new_setting_name\'
) ) );
$wp_customize->add_setting( \'starter_new_setting_name2\' , array(
\'default\' => \'#AAAFFF\',
\'transport\' => \'refresh\',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, \'link_color\', array(
\'label\' => __( \'H2 Color\', \'starter2\' ),
\'section\' => \'starter_new_section_name\',
\'settings\' => \'starter_new_setting_name2\'
) ) );
}
add_action( \'customize_register\', \'starter_customize_register\');
我试过这个人的密码(
source) 这在有多个部分时有效,但不适用于上面的颜色:
function mcs_social($wp_customize){
$wp_customize->add_section(\'mcs_social_handle\', array(
\'title\' => __(\'Social Network Handles\', \'mcs\'),
\'description\' => \'i.e., Acme Company\\\'s Facebook is https://facebook.com/acmecompany then enter "acmecompany"\',
\'priority\' => 70,
));
// =============================
// = Facebook =
// =============================
$wp_customize->add_setting(\'mcs_fb_op\', array(
\'default\' => \'\',
\'capability\' => \'edit_theme_options\',
\'type\' => \'theme_mod\',
));
$wp_customize->add_control(\'mcs_fb\', array(
\'label\' => __(\'Facebook Handle\', \'mcs\'),
\'section\' => \'mcs_social_handle\',
\'settings\' => \'mcs_fb_op\',
));
// =============================
// = Twitter =
// =============================
$wp_customize->add_setting(\'mcs_tw_op\', array(
\'default\' => \'\',
\'capability\' => \'edit_theme_options\',
\'type\' => \'theme_mod\',
));
$wp_customize->add_control(\'mcs_tw\', array(
\'label\' => __(\'Twitter Handle\', \'mcs\'),
\'section\' => \'mcs_social_handle\',
\'settings\' => \'mcs_tw_op\',
));
// =============================
// = RSS =
// =============================
$wp_customize->add_setting(\'mcs_rs_op\', array(
\'default\' => \'rss2_url\',
\'capability\' => \'edit_theme_options\',
\'type\' => \'theme_mod\',
));
$wp_customize->add_control( \'mcs_rs\', array(
\'settings\' => \'mcs_rs_op\',
\'label\' => \'RSS Feed\',
\'section\' => \'mcs_social_handle\',
\'type\' => \'select\',
\'choices\' => array(
\'rdf_url\' => \'RDF/RSS 1.0 feed\',
\'rss2_url\' => \'RSS 2.0 feed\',
\'atom_url\' => \'Atom feed\',
),
));
}
//add
add_action( \'customize_register\', \'mcs_social\' );
知道我哪里出错了吗?
最合适的回答,由SO网友:Jacob Peattie 整理而成
您有重复的控件ID:
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, \'link_color\', array(
以及:
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, \'link_color\', array(
他们都是
link_color
, 但他们需要唯一的ID。最简单的选择是使用设置ID:
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, \'starter_new_setting_name\', array(
以及:
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, \'starter_new_setting_name2\', array(