Theme customizer – settings order

If I add more than 5 Settings to a single section, the order of the settings gets weird.

For example:

// Link color
$wp_customize->add_setting( 'tonal_'.$themeslug.'_settings[link_color1]', array(
    'default'           => $themeOptions['link_color1'],
    'type'              => 'option',
    'sanitize_callback' => 'sanitize_hex_color',
    'capability'        => 'edit_theme_options',
    'transport'         => 'postMessage'
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'tonal_'.$themeslug.'_settings[link_color1]', array(
    'label'    => __( 'Link color1', 'tonal' ),
    'section'  => 'colors',
    'settings' => 'tonal_'.$themeslug.'_settings[link_color1]',
    'choices'  => '#ffffff'
) ) );

Further examples in a pastebin – no expiration time

The colors are numbered from 1 to 7, but in the settings they appear in that order: 2,1,3,4,6,5,7

Has anybody experienced the same?

Or does anybody even know how to solve this?

2 s
2

If you need them in a specific order, then give a priority value to the controls. Otherwise, their order is not defined and cannot be guaranteed.

If you don’t define a priority, then the control gets the default priority of “10”.

When two controls have the same priority, then the resulting order is undefined, because that’s how PHP works.

Leave a Comment