Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I use next code to render a select option in theme customizer:

$wp_customize->add_setting(
    'powered_by',
    array(
        'default' => 'wordpress',
    )
);

$wp_customize->add_control(
    'powered_by',
    array(
        'type' => 'select',
        'label' => 'This site is powered by:',
        'section' => 'example_section_one',
        'choices' => array(
            'wordpress' => 'WordPress',
            'hamsters' => 'Hamsters',
        ),
    )
);

Can I have to better format select control with many options?

I would like to have html output like this:

<select>
  <optgroup label="Swedish Cars">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
  </optgroup>
  <optgroup label="German Cars">
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
  </optgroup>
</select>

Thank you for your help!

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.