I am trying to remove certain items from Twenty Sixteen Customizer using this code
function my_customize_register() {
global $wp_customize;
$wp_customize->remove_section( 'colors' );
$wp_customize->remove_section( 'static_front_page' );
$wp_customize->remove_section( 'background_image' );
$wp_customize->remove_section( 'themes' );
$wp_customize->remove_panel( 'nav_menus' );
}
add_action( 'customize_register', 'my_customize_register', 11 );
However, for removing ‘Menus’ I am getting a debug message ‘WP_Customiz_Manager::remove_panel was called incorrectly. Rest everything working fine.
What should I do to remove ‘Menus’ itme?
1 Answer
Thanks Dharmishtha, but I found the answer in below stack which worked really well without throwing any debug errors:
How to remove menus section from WordPress theme customizer
The correct way to disable ‘Menus’ and ‘Widgets’ (in Customizer) lies in creating a plugin with below code (taken from the above mentioned post to make it convenient for others who might be searching for same answer).
/**
* 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' );
It can be done in other ways as well, but they throw a debug error.