Posted By

oneupdzn on 05/07/13


Tagged

menu php wordpress remove wp admin items


Versions (?)

Wordpress Remove Admin Menu Items


 / Published in: PHP
 

Remove top level menus and sub menus from the admin menu.

  1. /*================================================================
  2.   Remove Admin Menus
  3. ==================================================================*/
  4.  
  5. add_action( 'admin_menu', 'my_remove_menu_pages' );
  6. function my_remove_menu_pages() {
  7.  
  8. $remove_items = true; // SET TO FALSE TO SHOW ITEMS IN MENU
  9.  
  10. if($remove_items) {
  11.  
  12. /*================================================================
  13.   Remove Sub Menus
  14. ==================================================================*/
  15.  
  16. $submenus = array(
  17. 'cpt_main_menu', 'cpt_sub_add_new' // Top level menu is [0], sub menu is [1]
  18. ),
  19. 'EXAMPLE MENU', 'EXAMPLE SUB MENU'
  20. ));
  21.  
  22. foreach($submenus as $submenu) { // remove each sub menu in the $submenus array
  23. remove_submenu_page( $submenu[0], $submenu[1]);
  24. }
  25.  
  26. /*================================================================
  27.   Remove Top Level Menus
  28. ==================================================================*/
  29.  
  30. $slugs = array( // slugs of the top level menus to remove
  31. 'edit.php?post_type=acf',
  32. 'EXAMPLE MENU'
  33. );
  34.  
  35. foreach ($slugs as $slug) { // remove each menu in the $slugs array
  36. remove_menu_page($slug);
  37. }
  38. }
  39. }

Report this snippet  

You need to login to post a comment.