0

I added a section to the customizer and everything worked fine. But after I added a second one the first one no longer appears. At first I thought that I had not changed the section ID, but that was not the case. Here is some of my code:

/* ====================================================
     * Section 1
     =================================================== */
    // Add section
    $wp_customize->add_section("qs_spirit_co_section_1", array(
        "title" => __("First Widget Area", "qs-spirit-co"),
        "priority" => 1,
        "panel" => "widget_section_panel",
    ));

    // Section 1 text color
    $wp_customize->add_setting("qs_spirit_co_section_1_text_color", array(
        "default" => "#f8f8f8",
        "transport" => "refresh",
    ));

    $wp_customize->add_control(new WP_Customize_Color_Control(
        $wp_customize, "qs_spirit_co_section_2_text_color_control",
        array(
            "label" => __("Text Color", "qs-spirit-co"),
            "section" => "qs_spirit_co_section_1",
            "settings" => "qs_spirit_co_section_1_text_color",
            "type" => "color",
        )
    ));

/* ====================================================
     * Section 2
     =================================================== */
    // Add section
    $wp_customize->add_section("qs_spirit_co_section_2", array(
        "title" => __("Second Widget Area", "qs-spirit-co"),
        "priority" => 130,
        "panel" => "widget_section_panel",
    ));

    // Section 2 text color
    $wp_customize->add_setting("qs_spirit_co_section_2_text_color", array(
        "default" => "#535353",
        "transport" => "refresh",
    ));

    $wp_customize->add_control(new WP_Customize_Color_Control(
        $wp_customize, "qs_spirit_co_section_2_text_color_control",
        array(
            "label" => __("Text Color", "qs-spirit-co"),
            "section" => "qs_spirit_co_section_2",
            "settings" => "qs_spirit_co_section_2_text_color",
            "type" => "color",
        )
    ));

I even made a new panel for these sections but the first one still does not show when the second one is there. I removed the code for the second and the first appeared again.

I'm probably just missing something simple but I haven't found it yet. Could someone please help?

1

The problem is that you've got duplicate control IDs. In section 1 you have:

$wp_customize->add_control(new WP_Customize_Color_Control(
    $wp_customize, "qs_spirit_co_section_2_text_color_control",
    array(
        "label" => __("Text Color", "qs-spirit-co"),
        "section" => "qs_spirit_co_section_1",
        "settings" => "qs_spirit_co_section_1_text_color",
        "type" => "color",
    )
));

Which has qs_spirit_co_section_2_text_color_control as the ID.

And in section 2 you have:

$wp_customize->add_control(new WP_Customize_Color_Control(
    $wp_customize, "qs_spirit_co_section_2_text_color_control",
    array(
        "label" => __("Text Color", "qs-spirit-co"),
        "section" => "qs_spirit_co_section_2",
        "settings" => "qs_spirit_co_section_2_text_color",
        "type" => "color",
    )
));

Which is also using qs_spirit_co_section_2_text_color_control as the ID.

This means that only the first control is being added, to section 1, which means that section 2 has has no controls, and when sections have no controls they do not appear.

Make sure to give the controls unique IDs.

| improve this answer | |
  • Holy crap! I looked at that for half an hour, even checking specifically for that problem, and didn't see it. I would like to point out, though, that the second instance overrides the first, so it is the second one that shows and not the first. Thank you for the second set of eyes. – TLawson Aug 9 '19 at 2:45

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.