gpt4 book ai didi

menu - Wordpress 将子菜单添加到自定义菜单

转载 作者:行者123 更新时间:2023-12-04 11:28:03 25 4
gpt4 key购买 nike

在我正在创建的 wordpress 插件中,它正在创建一个带有子菜单页面的新顶级管理菜单。这是我的代码:

add_menu_page('Eastview Custom', 'Eastview Custom', 5,"eastview-custom");
add_submenu_page("eastview-custom","GLS Lunch Orders","GLS Lunch",5,'glsLunch','glsLunch');

所以这段代码创建了一个新的管理菜单,“Eastview Custom”。然后它添加了两个子链接:“Eastview Custom”和“GLS Lunch”。问题是我不希望“Eastview Custom”作为子链接。我希望唯一的子链接是“GLS Lunch”。我无法弄清楚如何做到这一点。谢谢你的帮助!

最佳答案

根据法典

In situations where a plugin is creating its own top-level menu, the first submenu will normally have the same link title as the top-level menu and hence the link will be duplicated. The duplicate link title can be avoided by calling the add_submenu_page function the first time with the parent_slug and menu_slug parameters being given the same value.



您可以在此页面上看到: http://codex.wordpress.org/Adding_Administration_Menus#Sub-Menus

因此,根据 Codex,您应该能够拥有以下内容(请注意,我已将您的用户级别参数替换为功能,因为它们已被弃用,并将其全部标准化为单引号);
add_menu_page('Eastview Custom', 'Eastview Custom', 'manage_options', 'my-top-level-handle');
add_submenu_page( 'my-top-level-handle', 'GLS Lunch Orders', 'GLS Lunch', 'manage_options', 'my-top-level-handle');

现在你会认为这会基于 Codex 起作用 - 事实并非如此。它不会仅仅因为只有一个子菜单项而显示任何子菜单项。如果您添加另一个项目,您会看到这是有效的,即;
add_menu_page('Eastview Custom', 'Eastview Custom', 'manage_options', 'my-top-level-handle');
add_submenu_page( 'my-top-level-handle', 'GLS Lunch Orders', 'GLS Lunch', 'manage_options', 'my-top-level-handle');
add_submenu_page( 'my-top-level-handle', 'New Item', 'New item', 'manage_options', 'new-handle');

希望这会有所帮助,可惜我找不到单个列表项的答案!

关于menu - Wordpress 将子菜单添加到自定义菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11613597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com