I would like to hide some submenus from the Dashboard for non admin users. I'm using the remove_submenu_page function but I'm not using it properly since it doesn't work and sub menus are still displayed. http://codex.wordpress.org/Function_Reference/remove_submenu_page

I'm trying to hide sub menus from a plugin called Newsletter for non admins :

  • wp-admin/admin.php?page=newsletter_main_index
  • wp-admin/admin.php?page=newsletter_main_main
  • wp-admin/admin.php?page=newsletter_main_diagnostic
  • wp-admin/admin.php?page=newsletter_subscription_profile

Here's the code I used in functions.php but I can't get it right:

    function ns_remove_admin_menus() {
        global $menu;
        global $current_user;
        if ($current_user->ID != 1) {
            remove_submenu_page( 'admin.php?page=', 'newsletter_main_index' );
            remove_submenu_page( 'admin.php', 'newsletter_main_index' );
    add_action('admin_init', 'ns_remove_admin_menus', 999 );

Any idea how I could make it work?


Use the action admin_menu as opposed to admin_init. You also need to adjust your use of remove_submenu_page to match the way Newsletter adds menu items:

remove_submenu_page( 'newsletter_main_index', 'newsletter_main_index' );
remove_submenu_page( 'newsletter_main_index', 'newsletter_main_main' );
remove_submenu_page( 'newsletter_main_index', 'newsletter_main_diagnostic' );
remove_submenu_page( 'newsletter_main_index', 'newsletter_subscription_profile' );
| improve this answer | |
  • Tried remove_submenu_page( 'admin.php', 'newsletter_main_index' ); remove_submenu_page( 'admin', 'newsletter_main_index' ); add_action('admin_menu', 'ns_remove_admin_menus', 999 ); with no luck – Kimberley Furson Apr 2 '14 at 17:38
  • Do you want to remove the whole of "Newsletter" from the admin menu, or just sub menu items from "Newsletter"? – TheDeadMedic Apr 2 '14 at 17:42
  • Only submenus items (the ones listed in my initial post). – Kimberley Furson Apr 2 '14 at 17:46
  • Gotcha. See revised answer. – TheDeadMedic Apr 2 '14 at 17:49
  • I thought the id slug for the parent menu was admin.php , thanks – Kimberley Furson Apr 2 '14 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.