【问题标题】:How to remove menus section from WordPress theme customizer如何从 WordPress 主题定制器中删除菜单部分
【发布时间】:2016-12-25 21:55:32
【问题描述】:

我试图从 WordPress 定制器中删除菜单查看图片

我在functions.php文件上尝试了以下代码,除了菜单之外的每个部分都被删除了

  //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' );

我什至尝试过

$wp_customize->remove_panel( 'menus');

但没有奏效,我提前感谢任何帮助。

【问题讨论】:

  • 你的主题有customizer.php吗?

标签: wordpress wordpress-theming


【解决方案1】:

你可以试试这个。

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-18
      • 2022-12-25
      • 2012-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-23
      • 1970-01-01
      相关资源
      最近更新 更多