1

I'm creating two color controls using the Customizer.

function main_salvio_customizer( $wp_customize ) {

    $wp_customize->add_setting( 'page-title-section' , array(
        'default'   => '#3c93bd',
        'transport' => 'postMessage',
    ) );

    $wp_customize->add_setting( 'page-title-section-text-color' , array(
        'default'   => '#000000',
        'transport' => 'postMessage',
    ) );

    $wp_customize->add_section( 'personalize-color-page' , array(
    'title'      => __( 'Visible Section Name' ),
    'priority'   => 30,
    ) );

     $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array(
    'label'      => __( 'Page Text Color' ),
    'settings'   => 'page-title-section-text-color',
        'section'    => 'personalize-color-page',
    ) ) ); 

    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array(
    'label'      => __( 'Page Title Control' ),
    'settings'   => 'page-title-section',
        'section'    => 'personalize-color-page',
    ) ) );  
}
add_action( 'customize_register', 'main_salvio_customizer' );

The issue is that I can only see the last added control, if change the order Page Text Color appears and the other is gone.

2

WP_Customize_Color_Control takes 3 parameters:

/**
 * @param WP_Customize_Manager $manager Customizer bootstrap instance.
 * @param string $id Control ID.
 * @param array $args Optional. Arguments to override class property defaults.
 */

The problem with the original code is that you've passed the same Control ID (link_color) to two separate instances. So, the most recently added control stomps on the previous one with the same Control ID. Make sure to give your controls unique ids.

Here's the revised code with unique Control IDs for each color control:

add_action( 'customize_register', 'main_salvio_customizer' );
function main_salvio_customizer( $wp_customize ) {

    $wp_customize->add_section( 'personalize-color-page', array(
        'title'         => __( 'Visible Section Name', 'text-domain' ),
        'priority'  => 30,
    ) );

    $wp_customize->add_setting( 'page-title-section', array(
            'default'       => '#3c93bd',
            'transport' => 'postMessage',
    ) );

    $wp_customize->add_setting( 'page-title-section-text-color' , array(
            'default'   => '#000000',
            'transport' => 'postMessage',
    ) );

    // Control ID page_text_color
    $wp_customize->add_control(
        new WP_Customize_Color_Control( $wp_customize, 'page_text_color', array(
            'label'    => __( 'Page Text Color', 'text-domain' ),
            'settings' => 'page-title-section-text-color',
            'section'  => 'personalize-color-page',
        ) )
    ); 

    // Control ID page_title_color
    $wp_customize->add_control(
        new WP_Customize_Color_Control( $wp_customize, 'page_title_color', array(
            'label'    => __( 'Page Title Control', 'text-domain' ),
            'settings' => 'page-title-section',
            'section'    => 'personalize-color-page',
        ) )
    );  
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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