无法将任何控件/设置添加到nav_menus
因为那不是一个部分,那是一个面板。和控制/设置只能添加到节中。因此,您必须首先在nav_menus
面板,然后将控件/设置添加到该部分。检查以下代码
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
您必须添加节
description
要创建类似于外观的菜单位置,如果要更改节位置,可以设置
priority
.
priority => 5
将在菜单位置之前放置自定义部分,如果这样做,则可能需要调整一些样式。请检查下面的代码以获取更新的节配置。
$wp_customize->add_section( \'nav_menus_custom\', array(
\'title\' => __( \'Custom Section Title\', \'nssra\' ),
\'panel\' => \'nav_menus\',
\'description\' => __( \'Section description goes here.\', \'nssra\' ),
\'priority\' => 5
) );