This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies.
The following code below will disable menus items on the WordPress admin area, this code snippet can be used on your theme’s functions.php or can just create a plugin for it.
Some consideration you should know before you use this code snippet:
1 – The menu items will not be visible for for all the users.
2 – This code snippet only removes the menu items the URL for the menu items will stay available
add_action( 'admin_menu', 'ns_menulinks_remove' ); function ns_menulinks_remove() { remove_menu_page( ' index.php ' ); // This is for Dashboard remove_menu_page( ' edit.php ' ); // This is for Posts remove_menu_page( ' upload.php ' ); // This is for Media remove_menu_page( ' link-manager.php ' ); // This is for Links remove_menu_page( ' edit.php?post_type=page ' ); // This is for Pages remove_menu_page( ' edit-comments.php ' ); // This is for Comments remove_menu_page( ' themes.php ' ); // This is for Appearance remove_menu_page( ' plugins.php ' ); // This is for Plugins remove_menu_page( ' users.php ' ); //This is for Users remove_menu_page( ' tools.php ' ); // This is for Tools remove_menu_page( ' options-general.php ' ); // This is for Settings }
Similar to the code above the code snippet below will disable the menu items on the WordPress admin area but only for a specific group of uses.
Some consideration you should know before you use this code snippet:
1 – Please change ‘array( 1, 2 )’ with the user ID that you want to allow to show the menu items
2 – This code snippet only removes the menu items the URL for the menu items will stay available
add_action( 'admin_menu', 'ns_remove_menus', 999 ); function ns_remove_menus() { $ns_current_user_id = $current_user->ID; // get the user ID $ns_team_ids = array( 1, 2 ); /* if current user id is not in the allowed array */ if( ! in_array( $ns_current_user_id, $ns_team_ids ) ) { /* remove the menu items(s) */ remove_menu_page(‘options-general.php’); } }
You may be interested to know how to add an admin menu item with admin page on WordPress, please click here to find out more.
Relevant reading here “WordPress Menu User Guide”