[英]How do I get “posts” to show up in the admin sidebar in wordpress?
I am removing all items that I do not want on the sidebar and I thought it would be easier to tell wordpress what I want to show up instead of what I dont want to show up so that if things get added in the future they wont show up on the side bar by default. 我正在删除侧边栏上所有我不想要的项目,我认为告诉wordpress我想要显示的内容比我不想显示的内容更容易,这样如果将来添加东西,它们就不会显示默认情况下位于侧栏上
I have added this code and everything is showing up like it should except for posts and the logout link that I have at the bottom. 我已经添加了此代码,除了我在底部的帖子和注销链接之外,其他所有内容都应按预期显示。 Can anyone help me figure this out? 谁能帮我解决这个问题? I know I am using the correct slug so Im not sure why its not working. 我知道我使用的是正确的子弹,所以我不确定为什么它不起作用。
add_action('admin_init', 'nwcm_admin_init');
function nwcm_admin_init()
{
if (!current_user_can('editor')) {
return;
}
$menus_to_stay = array(
'index.php',
'edit.php',
'upload.php',
'edit.php?post_type=page',
'nav-menus.php',
'post-new.php',
'admin.php?page=logout'
);
foreach ($GLOBALS['menu'] as $key => $value) {
if (!in_array($value[2], $menus_to_stay))
remove_menu_page($value[2]);
}
}
I need to do this in functions.php and not with a plugin so please dont recommend plugins! 我需要在functions.php中而不是使用插件来执行此操作,所以请不要推荐插件!
Your action is not correct, use admin_menu
您的操作不正确,请使用admin_menu
https://codex.wordpress.org/Function_Reference/remove_menu_page https://codex.wordpress.org/Function_Reference/remove_menu_page
add_action('admin_menu', 'nwcm_admin_init');
function nwcm_admin_init()
{
if (!current_user_can('editor'))
return;
$menus_to_stay = array(
'index.php',
'edit.php',
'upload.php',
'edit.php?post_type=page',
'nav-menus.php',
'post-new.php',
'admin.php?page=logout'
);
foreach ($GLOBALS['menu'] as $key => $value) {
if (!in_array($value[2], $menus_to_stay))
remove_menu_page($value[2]);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.