Remove sub menu items

2019-09-07 15:00发布

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.

3条回答
老娘就宠你
2楼-- · 2019-09-07 15:35

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');
}
查看更多
Juvenile、少年°
3楼-- · 2019-09-07 15:48

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 );
查看更多
狗以群分
4楼-- · 2019-09-07 15:54

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');
}
查看更多
登录 后发表回答