简体   繁体   English

如何在Wordpress的管理侧栏中显示“帖子”?

[英]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.

相关问题 如何显示所有帖子,但在wordpress上排除特定类别? - How do I show all posts but exclude a specific category on wordpress? 如何在 WordPress 中为 get_posts() 进行分页? - How do I get pagination to work for get_posts() in WordPress? 如何从WordPress存档中获取帖子? - How do I get_posts from an Archive in WordPress? 如何从侧边栏中的单页自定义帖子类型获取帖子以显示在页面中? - How do I get the posts from single page custom post type from a sidebar to display in a page? 如何删除自定义帖子类型管理屏幕中出现的所有Wordpress帖子? - How do I remove all Wordpress Posts from appearing in my Custom Post Type admin screen? WordPress功能“ register_post_type”未显示在管理员左侧边栏中 - WordPress function “register_post_type” does not show up in the admin left sidebar 如何在WordPress边栏中正确编码以仅显示类别中最近1个月的帖子 - How correct code in WordPress sidebar to show only posts from last 1 month from category 如何设置交替的WordPress帖子的样式? - How do I style alternating WordPress posts? WordPress,我如何AJAX附加帖子 - WordPress, How Do I AJAX Additional Posts 错误的wordpress,调整了sidebar.php以显示最新的10个帖子 - error wordpress, adjusted sidebar.php to show latest 10 posts
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM