Is it possible to limit maximum menu depth in admin panel /nav-menus.php?

I need this because my theme won't support more than two levels of menu, so there is no point in allowing a user to make deeper menus.


The solution that I came up with:

 * Limit max menu depth in admin panel to 2
function q242068_limit_depth( $hook ) {
  if ( $hook != 'nav-menus.php' ) return;

  // override default value right after 'nav-menu' JS
  wp_add_inline_script( 'nav-menu', 'wpNavMenu.options.globalMaxDepth = 1;', 'after' );
add_action( 'admin_enqueue_scripts', 'q242068_limit_depth' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.