Admin & Dashboard PHP Beginner

Hide Admin Menu Items From Non-Administrators

Remove menu items like Tools and Comments for editors and other roles, so clients only see what they use.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 10 lines
add_action( 'admin_menu', function (): void {
	if ( current_user_can( 'manage_options' ) ) {
		return;
	}

	remove_menu_page( 'tools.php' );          // Tools.
	remove_menu_page( 'edit-comments.php' );  // Comments.
	// remove_menu_page( 'edit.php' );        // Posts.
	// remove_menu_page( 'upload.php' );      // Media.
}, 999 );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

Editors and shop managers see menu items they never use. A shorter menu makes wp-admin less intimidating for clients and cuts down on “what does this do?” questions.

How it works

remove_menu_page() takes the file name from the menu item’s link, such as tools.php. The callback runs late on admin_menu, after plugins have added their own items, and only for users who aren’t administrators.

Plugin menus use their page slug: for admin.php?page=wpcf7 it’s wpcf7.

Things to watch

  • This hides the menu items only. Users can still visit the pages directly if their role allows it. To block access, remove the capability from the role instead.
  • Hover over a menu item to see its link in the browser’s status bar.

How to test it

Log in as an editor. Tools and Comments should be missing from the menu.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only