如何从WordPress主题定制器中删除菜单部分

我试图从WordPress定制程序中删除菜单

如何从WordPress主题定制器中删除菜单部分

文章图片
我在functions.php文件上尝试了以下代码, 除菜单外的每个部分均被删除
//Theme customizerfunction 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' );

我什至试过
$wp_customize-> remove_panel( 'menus');

但没有用, 我在此先感谢任何帮助。
#1 【如何从WordPress主题定制器中删除菜单部分】你可以试试看
function remove_customizer_settings( $wp_customize ){$wp_customize-> remove_panel('nav_menus'); } add_action( 'customize_register', 'remove_customizer_settings', 20 );

#2 上面的答案对我来说不起作用, 但是起作用的东西要复杂得多。我在http://wordpress.stackexchange.com/questions/228770/remove-nav-menus-from-customizer-using-a-theme找到了答案, 但是这里又是。将以下内容添加到主题的functions.php文件中。
add_action('customize_register', function ( $WP_Customize_Manager ){ //check if WP_Customize_Nav_Menus object exist if (isset($WP_Customize_Manager-> nav_menus) & & is_object($WP_Customize_Manager-> nav_menus)) {//Remove all the filters/actions resiterd in WP_Customize_Nav_Menus __construct remove_filter( 'customize_refresh_nonces', array( $WP_Customize_Manager-> nav_menus, 'filter_nonces' ) ); remove_action( 'wp_ajax_load-available-menu-items-customizer', array( $WP_Customize_Manager-> nav_menus, 'ajax_load_available_items' ) ); remove_action( 'wp_ajax_search-available-menu-items-customizer', array( $WP_Customize_Manager-> nav_menus, 'ajax_search_available_items' ) ); remove_action( 'customize_controls_enqueue_scripts', array( $WP_Customize_Manager-> nav_menus, 'enqueue_scripts' ) ); remove_action( 'customize_register', array( $WP_Customize_Manager-> nav_menus, 'customize_register' ), 11 ); remove_filter( 'customize_dynamic_setting_args', array( $WP_Customize_Manager-> nav_menus, 'filter_dynamic_setting_args' ), 10, 2 ); remove_filter( 'customize_dynamic_setting_class', array( $WP_Customize_Manager-> nav_menus, 'filter_dynamic_setting_class' ), 10, 3 ); remove_action( 'customize_controls_print_footer_scripts', array( $WP_Customize_Manager-> nav_menus, 'print_templates' ) ); remove_action( 'customize_controls_print_footer_scripts', array( $WP_Customize_Manager-> nav_menus, 'available_items_template' ) ); remove_action( 'customize_preview_init', array( $WP_Customize_Manager-> nav_menus, 'customize_preview_init' ) ); remove_filter( 'customize_dynamic_partial_args', array( $WP_Customize_Manager-> nav_menus, 'customize_dynamic_partial_args' ), 10, 2 ); } }, -1); //Give it a lowest priority so we can remove it on right time

    推荐阅读