How to remove menu item in WordPress admin panel

How can I hide menu or submenu items in WordPress admin dashboard according to the user’s role ?

Insert this code on your functions.php file or plugin:

[php]
/*
* Hide menu in admin panel for editors
*
*/
add_action( ‘admin_menu’, ‘wpster_remove_menu_items’, 999 );
function wpster_remove_menu_items() {
if( current_user_can(‘editor’)) {
remove_menu_page( ‘themes.php’ );
remove_menu_page( ‘edit.php?post_type=acf_option_page’ );
remove_submenu_page( ‘options-general.php’,’options-discussion.php’ );
}
}
[/php]

Please not that this function only hide the option, but the user can always access to the option!

Submit a Comment

Your email address will not be published. Required fields are marked *