您可以创建一个子菜单页面并作为其父页面传递null
:
$parent_slug
如果您想创建一个不出现在任何菜单中的页面,请使用 NULL 或设置为 'options.php'。
一个演示:
add_action('admin_menu', function()
{
# Main page
add_menu_page(
'Vsa',
'Vsa',
'add_users', // Capability, not role
'listaj-narocila',
function(){
printf(
'<h2>%s</h2><a href="%s">%s</a>',
__( 'Main page' ),
admin_url( 'admin.php?page=single-norcilo&id='.rand(1,25) ),
__( 'Hidden sub page' )
);
},
'http://sstatic.net/stackexchange/img/favicon.ico'
);
# Child page
$hook = add_submenu_page(
null,
'Norcilo',
'Norcilo',
'add_users',
'single-norcilo',
function(){
printf(
'<h2>%s</h2><a href="%s">%s</a>',
__( 'Hidden sub page' ),
admin_url( 'admin.php?page=listaj-narocila' ),
__( 'back' )
);
}
);
# Enqueue script in submenu page to fix the current menu indicator
add_action( "admin_footer-$hook", function()
{
echo <<<HTML
<script type="text/javascript">
jQuery(document).ready( function($) {
$('#toplevel_page_listaj-narocila')
.removeClass('wp-not-current-submenu')
.addClass('current');
});
</script>
HTML;
});
});
另一种方法:https ://wordpress.stackexchange.com/a/114818/12615