Remove sub menu items

五迷三道 提交于 2019-12-25 16:48:51

问题


I want to remove a few sub menu items from the admin menu in WordPress. I have found the following which can remove certain sub menu items...

add_action( 'admin_menu', 'adjust_the_wp_menu', 999 );
function adjust_the_wp_menu() {
  $page = remove_submenu_page( 'themes.php', 'widgets.php' );
}

...but what if it is not a standard php such as "themes.php?page=custom-header" that I would like removed.


回答1:


Add code in your function.php

Remove "themes.php?page=custom-header" option using this code.


function remove_twentyeleven_options() {
    remove_custom_image_header();
}
add_action( 'after_setup_theme','remove_twentyeleven_options', 100 );



回答2:


This worked for me. Thanks to Ravi for pointing me in the right direction.

add_action( 'init', 'remove_taxonomy_menu_pages', 999 );
function remove_taxonomy_menu_pages() {
    // remove products->categories
    register_taxonomy('product_cat', 
        'woocommerce_taxonomy_objects_product_cat', array('show_ui' => false)
    );
    // remove products->tags
    register_taxonomy('product_tag', 
        'woocommerce_taxonomy_objects_product_tag', array('show_ui' => false)
    );
    // remove products->shipping classes
    register_taxonomy('product_shipping_class', 
        'woocommerce_taxonomy_objects_product_shipping_class', array('show_ui' => false)
    );
}
add_action( 'admin_menu', 'remove_submenu_pages', 999 );
function remove_submenu_pages() {
    // remove products->attributes
    remove_submenu_page( 'edit.php?post_type=product', 'woocommerce_attributes');
}



回答3:


I would like to share, that's how you can remove woocommerce submenu's

  • Product Attributes
  • Product Shipping Class

--

add_action( 'admin_menu', 'remove_taxonomy_menu_pages', 999 );
function remove_taxonomy_menu_pages() {
    remove_submenu_page( 'edit.php?post_type=product', 'product_attributes' );
    remove_submenu_page( 'edit.php?post_type=product', 'edit-tags.php?taxonomy=product_shipping_class&post_type=product');
}


来源:https://stackoverflow.com/questions/16703391/remove-sub-menu-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!