Support » Developing with WordPress » Customizer keeps hiding custom sections.

  • Resolved vincurekf

    (@vincurekf)


    Hello,

    I have custom plugin that adds Customizer sections and options.
    The sections can be seen briefly on the customizer screen but then disappear (with added inline css style “display: none;”).

    I am using the default Twenty Nineteen theme, only active plugin is jQuery updater and my own plugin. I’ve checked my JS code and the hiding is not happening due to my code.

    This behavior is happening on all themes (I am using my plugin on other sites).

    The way I am setting up the sections, setting and control:

    
    // Add section
    $wp_customize->add_section('section_id', array(
      'title'    => 'Section Title',
      'priority' => 160,
    ));
    // Add settings for a field
    $wp_customize->add_setting('setting_id', array(
      'default'   => '',
      'transport' => 'refresh',
    ));
    // Add the field into a section and assign control
    $wp_customize->add_control('setting_id', array(
      'label'    => 'Option Label,
      'section'  => 'section_id',
      'settings' => 'setting_id',
      'type'     => 'text',
    ));
    

    As I said, the sections are visible for a second, then all my custom sections are hidden.

    Maybe it might be because none of the setting fields are not yet used in the theme but even if I create my own theme (for which this plugin is mainly used) and add echo get_theme_mod('setting-key') somewhere in the themes code, the sections are still being hidden by wordpress.

    Is there some new Customizer API option to keep sections always visible or something that I overlooked? I can’t find anything on google or in WordPress Documentation.

    Thank you for your help.

    • This topic was modified 3 years, 9 months ago by vincurekf. Reason: theme name

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • You have to give the section a different name than the setting and control.
    Edit: Ah, ignore that. I misread.
    Try putting your control on an existing section, just to see if it works.
    Also, are all the top levels in the Cutomizer defined as panels, or sections?

    • This reply was modified 3 years, 9 months ago by Joy. Reason: oops
    Thread Starter vincurekf

    (@vincurekf)

    Thank you for your reply @joyously , hoever, can you please share some example code? Going by the documentation I should be good. The options are rendered in the HTML. They are visible when inspecting the code. But they are being hidden after page load by, I assume, wordpress.

    Can you please provide me with example code?

    EDIT: All the top levels are defined as sections.
    Here is how I currently do it:
    https://pastebin.com/8LWxRpQT

    Basic setup, following the documentation.

    • This reply was modified 3 years, 9 months ago by vincurekf.
    • This reply was modified 3 years, 9 months ago by vincurekf. Reason: example pastebin

    Check the Code Reference for parameters that cause sections or controls to be hidden.
    https://developer.wordpress.org/reference/classes/wp_customize_manager/add_section/
    The default capability is edit_theme_options.

    https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting/
    Same default capability, but default type is theme_mod, which doesn’t sound correct for a plugin.

    https://developer.wordpress.org/reference/classes/wp_customize_manager/add_control/
    The settings parameter is an array, and your code is not.

    Thread Starter vincurekf

    (@vincurekf)

    To add to your previous reply. I’ve had custom options in title_tagline, a text field and image field. Both hidden right after page loaded. Inspecting the code, I foud that both, li section elements and li control elements have style="display: none;" added.

    And I am 100% sure I am not hiding them.
    Just recently, before updating WordPress to version 5.2.2, everything worked fine.

    Thread Starter vincurekf

    (@vincurekf)

    Solved it. Thank you for your time Joy!

    In the end it was my fault. I was setting up the options only inside if(is_admin()) check, not realizing that the options should be created for the fronend too. This in turn affected the customizer UI after the preview iframe was reloaded.

    It’s still pretty weird behavior.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Customizer keeps hiding custom sections.’ is closed to new replies.