0

I'd like to add multiple options for the Color section of Wordpress Customizer, this is my code (the lower code (starter_new_setting_name2) overrides the upper):

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');

I have tried this person's code (source) and that worked in having multiple sections but not for the color above:

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' );

Any idea where I went wrong?

1 Answer 1

1

You've got duplicate control IDs:

$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array(

And:

$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array(

They're both link_color, but they need unique IDs. Simplest option is to use the setting IDs:

$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'starter_new_setting_name', array(

And:

$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'starter_new_setting_name2', array(
3
  • Ah, I was thinking that link_color is a fixed setting. Thanks for the help, Jacob Peattie, made your response the accepted answer :), I still am not eligible for the +1, sorry. Mind helping with this?: link
    – Veneripmi
    Commented Aug 9, 2019 at 8:02
  • I'm not well versed on localization I'm afraid. Commented Aug 9, 2019 at 8:25
  • It's alright, thanks anyway.
    – Veneripmi
    Commented Aug 9, 2019 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.