主菜单链接也显示在 WP 管理面板的子菜单上 [英] Main menu link also showing on submenu in WP admin panel
问题描述
我在管理面板中创建了一个自定义顶部菜单,并为该菜单添加了两个子菜单.我的代码如下:
I have created a custom top menu in admin panel and also add two submenu for that menu. my code is as follows:
add_action('admin_menu', 'my_create_menu');
function my_create_menu() {
add_menu_page('My custom menu', 'My custom menu Settings', 'manage_options', __FILE__, 'my_custom_menu',plugins_url('assets/images/test.png', __FILE__));
add_submenu_page( __FILE__ , 'My custom submenu-1', 'My custom submenu-1', 'manage_options', 'sub-suge', 'my_custom_submenu_1');
add_submenu_page( __FILE__ , 'My custom submenu-2', 'My custom submenu-2', 'manage_options', 'sub-page', 'my_custom_submenu_2');
add_action( 'admin_init', 'my_custom_menu' );
}
我的问题是当我为上面的顶部主菜单创建子菜单时,它会在子菜单的位置给出一个顶部菜单链接
,这意味着它给出了3个子菜单包括主菜单链接代码>.请参阅下面的链接示例输出.
My problem is when i create submenu for the above top main menu then it gives a top menu link
in the position of the submenu, that means it gives 3 submenu include main menu link
. Please see the below link example output.
http://jaskokoyn.com/2013/03/20/wordpress-admin-submenus/
但我不希望主菜单链接到子菜单.我只想要主菜单下的两个子菜单
我在代码中定义的内容.
But i don't want main menu link into sub menu. I just want two Submenu under main menu
what i have define in my code.
谁能为此提供更好的解决方案?
Can anyone give any better solution for this?
提前致谢.
推荐答案
您可以通过为顶级页面(add_menu_page()
调用)提供与第一个子菜单页面相同的 slug 来实现此目的.然后在两个 add_submenu_page()
调用的第一个参数中引用这个 slug.
You can achieve this by giving the top-level page (the add_menu_page()
call) the same slug as the first submenu page. Then reference this slug in the first parameter of both add_submenu_page()
calls.
代码如下:
add_menu_page(
'My custom menu Settings',
'My custom menu Settings',
'manage_options',
'sub-suge',
'my_custom_menu',
plugins_url( 'assets/images/test.png', __FILE__ )
);
add_submenu_page(
'sub-suge' ,
'My custom submenu-1',
'My custom submenu-1',
'manage_options',
'sub-suge',
'my_custom_submenu_1'
);
add_submenu_page(
'sub-suge' ,
'My custom submenu-2',
'My custom submenu-2',
'manage_options',
'sub-page',
'my_custom_submenu_2'
);
这篇关于主菜单链接也显示在 WP 管理面板的子菜单上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!