admin管理员组

文章数量:1417442

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?

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?

Share Improve this question asked Aug 8, 2019 at 3:01 TLawsonTLawson 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 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.

本文标签: Customizer section gone after adding second