Today I finally found out how to easily customize the Admin Menu and the Admin Toolbar for the Editor role of my clients, so they only see what they really really need. There are plugins doing the same and even much more, as the Adminimizer, but it offers too much for my simple needs. For most clients I need just a few lines of code for my functions.php. Reading through the WordPress Codex was enough, and here is what I did:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
function remove_admin_menu_items() { if (current_user_can('editor')) { 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 remove_menu_page( 'edit.php?post_type=project' ); //DIVI Projects } } add_action( 'admin_menu', 'remove_admin_menu_items', 999 ); function remove_admin_bar_items ($wp_admin_bar) { if (current_user_can('editor')) { $wp_admin_bar->remove_node('wp-logo'); // Remove the WordPress logo including all its submenu items //$wp_admin_bar->remove_node('site-name'); // Remove the site name menu //$wp_admin_bar->remove_node('view-site'); // Remove the view site link $wp_admin_bar->remove_node('updates'); // Remove the updates link $wp_admin_bar->remove_node('comments'); // Remove the comments link //$wp_admin_bar->remove_node('new-content'); // Remove the complete new content link //$wp_admin_bar->remove_node('my-account'); // Remove the user details tab $wp_admin_bar->remove_node('new-project'); // Remove only New DIVI Project from the content link } } add_action( 'admin_bar_menu', 'remove_admin_bar_items', 999 ); |
Just add this code into the functions.php of your child-theme and adapt it to your needs. I left all the default items and just commented them out with //. In this way we can easily adapt everything specific to each client by commenting/uncommenting. The last line is only relevant for the DIVI Theme.
Find more information on customizing the Admin Menu in the WordPress Codex on these pages:
https://codex.wordpress.org/Function_Reference/remove_menu_page
https://codex.wordpress.org/Function_Reference/remove_submenu_page
Find more information on customizing the Admin Toolbar in the WordPress Codex on these pages:
https://codex.wordpress.org/Function_Reference/remove_node
Find more information on conditioning functions according to the user role or capabilities:
https://codex.wordpress.org/Function_Reference/current_user_can
https://codex.wordpress.org/Roles_and_Capabilities
Enjoy creating your perfect WordPress for your wonderful clients. If you want them to have access to the Widget and Menu area without giving access to the whole Theme Customization, this article might be interesting for you.
Hi Sofian, thank you for this great post!
I have a question about hiding menu items like DIVI or others.
I used this code:
remove_menu_page( ‘admin.php?page=wpseo_dashboard’ ); //YOAST SEO
remove_menu_page( ‘admin.php?page=et_divi_options’ ); //DIVI
remove_menu_page( ‘admin.php?page=gadash_settings’ ); //GA
But unfortunately only the Yoast link disappears. Nothing else. Do you have an idea what to do?
Would be great hearing from you.
Best regards,
Alvaro
Got it.
remove_menu_page( ‘wpseo_dashboard’ ); //YOAST SEO
remove_menu_page( ‘et_divi_options’ ); //DIVI
remove_menu_page( ‘gadash_settings’ ); //GA
Thanks again!!