Hide Admin menu on WordPress Backend
There are many reasons why you want to lessen the menus on the backend of WordPress. Some of these are
- To make the backend as minimal as possible.
- To make your theme design secure. You don’t want other administrator to edit it and mess around with it.
- You just feel like other features are not needed.
There are still other more reasons as to why we do it, nonetheless, see the snippet code that you can use for this below.
Create a function that looks like this. This sample and the code is very verbose and by simply looking into it I think you can understand already what it does.
function remove_admin_menus() {
remove_menu_page( 'index.php' ); // Dashboard
remove_menu_page( 'edit.php' ); // Posts
remove_menu_page( 'upload.php' ); // Media
remove_menu_page( 'edit.php?post_type=page' ); // Pages
remove_menu_page( 'themes.php' ); // Appearance
remove_menu_page( 'plugins.php' ); // Plugins
remove_menu_page( 'users.php' ); // Users
remove_menu_page( 'options-general.php' ); // Settings
remove_menu_page( 'edit-comments.php' ); /** Comments */
remove_menu_page( 'tools.php' ); /** Tools */
}
After that you need to hook into for WordPress to be able to properly run the function.
add_action( 'admin_init', array( $this, 'remove_admin_menus' ), 11 );
That’s it! You can add different kind of conditional statement inside the function, depending on the needed requirements.