In this post, I am going to show how you can easily remove menus and submenu links from WordPress dashboard, and also how to order them in the way you want in WordPress 3.1.
Remove Menu Page Links
WordPress 3.1 comes with a built-in function that allows quick and easy removal of any of the default menus from the dashboard.
This is the complete list of default menu pages:
function delete_menu_items() { remove_menu_page('index.php'); // Dashboard remove_menu_page('edit.php'); // Posts remove_menu_page('upload.php'); // Media remove_menu_page('link-manager.php'); // Links 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 } add_action( 'admin_init', 'delete_menu_items' );
Keep the one’s you want to remove and add the code to the theme’s functions.php
file.
Remove Menu Page Links Based on Roles
You can also remove menu pages for users based on roles. The below code will remove the Tools and Settings links only for Editors:
function delete_menu_items() { if ( current_user_can( 'editor' )) { remove_menu_page('tools.php'); // Tools remove_menu_page('options-general.php'); // Settings } } add_action( 'admin_init', 'delete_menu_items' );
Remove Submenu Page Links
WordPress also lets you remove submenu links from a menu.
To remove a submenu page, you need to include both the menu and submenu slug in the function.
Below code will remove the Widgets and theme Editor link, found under the Appearance menu. You can get a preview of it in the above image.
function delete_submenu_items() { remove_submenu_page( 'themes.php', 'widgets.php' ); remove_submenu_page( 'themes.php', 'theme-editor.php'); } add_action( 'admin_init', 'delete_submenu_items' );
Remove Submenu Page Links Based on Roles
Submenus can also be removed based on user role. This will remove the theme Editor link only for Editors.
function delete_submenu_items() { if ( current_user_can( 'editor' )) { remove_submenu_page( 'themes.php', 'theme-editor.php'); } } add_action( 'admin_init', 'delete_submenu_items' );
Reorder Menu Links
Now that you only have the links you need in the menu, they can also be ordered the way you want.
This is the default order of menu links:
function custom_menu_order($menu_ord) { if (!$menu_ord) return true; return array( 'index.php', // Dashboard 'edit.php', // Posts 'upload.php', // Media 'link-manager.php', // Links 'edit.php?post_type=page', // Pages 'edit-comments.php', // Comments 'themes.php', // Appearance 'plugins.php', // Plugins 'users.php', // Users 'tools.php', // Tools 'options-general.php' // Settings ); } add_filter('custom_menu_order', 'custom_menu_order'); add_filter('menu_order', 'custom_menu_order');
Organize the menu in the order you want and add the code to your theme’s functions.php
file. Don’t add those menu links which you don’t want to order. They will still appear but as per the default layout.