2

I tried to remove Menus from WordPress customizer (see image) enter image description here

I tried the following code on functions.php file and every section was removed except Menus

  //Theme customizer

function mytheme_customize_register( $wp_customize ) {
   //All our sections, settings, and controls will be added here

   $wp_customize->remove_section( 'title_tagline');
   $wp_customize->remove_section( 'colors');
   $wp_customize->remove_section( 'header_image');
   $wp_customize->remove_section( 'background_image');
   $wp_customize->remove_section( 'menus');
   $wp_customize->remove_section( 'static_front_page');
   $wp_customize->remove_section( 'custom_css');

}

add_action( 'customize_register', 'mytheme_customize_register' );

I even tried

$wp_customize->remove_panel( 'menus');

but didn't worked i m'i missing something here .appreciate any help on this thanks in advance.

3 Answers 3

9

Try nav_menus instead of menus with remove_panel()

function mytheme_customize_register( $wp_customize ) {
  //All our sections, settings, and controls will be added here

  $wp_customize->remove_section( 'title_tagline');
  $wp_customize->remove_section( 'colors');
  $wp_customize->remove_section( 'header_image');
  $wp_customize->remove_section( 'background_image');
  $wp_customize->remove_panel( 'nav_menus');
  $wp_customize->remove_section( 'static_front_page');
  $wp_customize->remove_section( 'custom_css');

}
add_action( 'customize_register', 'mytheme_customize_register',50 );

Hope this will helps you.

Thank you!

1
  • 4
    It should be noted that the "50" here in the add_action call is important. If it is omitted, this will not remove the nav_menus panel.
    – kloddant
    Jan 12, 2018 at 15:23
6

The correct way to disable nav menus in the customizer is via the customize_loaded_components filter as documented on its hook reference page:

/**
 * Removes the core 'Menus' panel from the Customizer.
 *
 * @param array $components Core Customizer components list.
 * @return array (Maybe) modified components list.
 */
function wpdocs_remove_nav_menus_panel( $components ) {
    $i = array_search( 'nav_menus', $components );
    if ( false !== $i ) {
        unset( $components[ $i ] );
    }
    return $components;
}
add_filter( 'customize_loaded_components', 'wpdocs_remove_nav_menus_panel' );

Important: this filter has to be added in a plugin since it has to be added before the setup_theme action, which fires just before a theme's functions.php is loaded.

For more information, see these Trac tickets:

  • #33552: Facilitate plugins to override Customizer features
  • #37003: Removing menus support for a theme doesn't remove Menus section in Customizer

On a related note, for code that resets the customizer to a blank slate so you can add just your own items, see Resetting the Customizer to a Blank Slate.

1
-1

Edit files in admin directory on your server. Even though you may find a plugin for this job. This will help you since it will have a UI and will not restore your menu when updating your wordpress or theme.

3
  • Can you tell which files to edit?
    – bravokeyl
    Dec 26, 2016 at 5:29
  • 2
    Do not do this. Editing core files will either break upgrades or the edits will be lost when upgrading. Dec 26, 2016 at 6:54
  • You don't say! I thought I said the SAME EXACT thing about updates in my answer. But THANKS for letting me know.
    – mxUser127
    Dec 26, 2016 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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