How can I move admin menu top-level items to submenu

独自空忆成欢 提交于 2019-12-11 14:32:38

问题


I'm using the code at https://markwilkinson.me/2014/11/altering-wordpress-admin-menus/ to change plugin-created top-level admin-menu items to submenu items of a 'misc' top-level item.

It works fine on those items which don't have their own submenu, but on items which have their own submenu the submenu disappears.

I don't know if the code can be appropriately modified, or if it can how to do it.


回答1:


Wordpress does not allow you to add a 3rd level of menus in WP admin.

See the answer to How to Add a Third Level Sub Menu to the Wordpress Admin Menu from wordpress.stackexchange.com

The answer from Karthikeyani explains why it currently isn't possible:

The definition of add_submenu_page requires the parent slug name. For example:

add_menu_page ( 'Test Menu', 'Test Menu', 'read', 'testmainmenu', '', '' );
add_submenu_page ( 'testmainmenu', 'Test Menu', 'Child1', 'read', 'child1', '');

The first parameter of the add_submenu_page is parent slug name $parent_slug. You may think you could use child1 ($menu_slug) as parent slug name to create the third level, but this does not work.

The parameters definition and source section in the Wordpress developer documentation for add_submenu_page clearly states that you can only use the name of the main menu of the plugin or the file name of the WordPress plugin in parent slug name.

add_submenu_page Ref: https://developer.wordpress.org/reference/functions/add_submenu_page/



来源:https://stackoverflow.com/questions/45791515/how-can-i-move-admin-menu-top-level-items-to-submenu

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