跟进@jmarceli对特定菜单位置的出色回答
function squarecandy_menu_admin_limit_depth( $hook ) {
if ( \'nav-menus.php\' !== $hook ) {
return;
}
wp_enqueue_script( \'squarecandy-admin-menu-depth\', get_stylesheet_directory_uri() . \'/js/admin-menu-depth.js\', array(), \'1.0.0\', true );
}
add_action( \'admin_enqueue_scripts\', \'squarecandy_menu_admin_limit_depth\' );
js公司
// Force Menu Depth to Match Front End
// main menu can only have one child level
if ( document.getElementById("locations-main-menu").checked ) {
wpNavMenu.options.globalMaxDepth = 1;
}
// footer menu have only top level
if ( document.getElementById("locations-footer-menu").checked ) {
wpNavMenu.options.globalMaxDepth = 0;
}
// all other menu locations stay at the WP default