You cannot add any control/setting to nav_menus
because that’s not a section that’s a panel. And control/setting can be added to the section only. So you have to create a section first under nav_menus
panel then add your control/setting to that section. Check the following code
function nssra_customizer_options( $wp_customize ) {
// add a custom section
$wp_customize->add_section( 'nav_menus_custom', array(
'title' => __( 'Custom Section Title', 'nssra' ),
'panel' => 'nav_menus'
) );
// add "menu primary flex" checkbox setting
$wp_customize->add_setting( 'menu_primary_flex', array(
'capability' => 'edit_theme_options',
'default' => '1',
'sanitize_callback' => 'nssra_sanitize_checkbox',
) );
// add 'menu primary flex' checkbox control
$wp_customize->add_control( 'menu_primary_flex', array(
'label' => __( 'Stretch the primary menu to fill the available space.', 'nssra' ),
'section' => 'nav_menus_custom',
'settings' => 'menu_primary_flex',
'std' => '1',
'type' => 'checkbox',
'priority' => 1,
));
}
add_action( 'customize_register', 'nssra_customizer_options' );
// sanitize checkbox fields
function nssra_sanitize_checkbox( $input, $setting ) {
return sanitize_key( $input ) === '1' ? 1 : 0;
}
Update
You have to add section description
to create the Menu Locations like appearance and if you want to change the section location then you can set priority
. priority => 5
will place the custom section before Menu Locations, if you do this then you may have to adjust some styling. Please check the code below for updated section config.
$wp_customize->add_section( 'nav_menus_custom', array(
'title' => __( 'Custom Section Title', 'nssra' ),
'panel' => 'nav_menus',
'description' => __( 'Section description goes here.', 'nssra' ),
'priority' => 5
) );