When customizing the WordPress Dashboard Screen for clients, you may want to hide or remove a few admin menu items to make things simpler for them.
Below is the code to remove specific admin menu items from users with low privilege. Note that this snippet only hides those admin menu items. They remain available if you type the correct URL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Remove admin menu items from users in WordPress | |
add_action( 'admin_menu', 'customprefix_remove_admin_menus', 10, 1 ); | |
function customprefix_remove_admin_menus( $context ) { | |
// Hide from users with low privilege | |
if ( ! current_user_can( 'manage_options' ) ) { | |
// Core 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( 'edit-comments.php' ); // Comments | |
remove_menu_page( 'themes.php' ); // Appearance | |
remove_menu_page( 'plugins.php' ); // Plugins | |
remove_menu_page( 'users.php' ); // Users | |
remove_menu_page( 'tools.php' ); // Tools | |
remove_menu_page( 'options-general.php' ); // Settings | |
// Plugins | |
remove_menu_page( 'jetpack' ); // Jetpack | |
} | |
} |