WordPress admin menus arethe links visible on the left side navigation in your admin area dashboard i.e /wp-admin screens. There are various ways of customizing these admin menus and we have discussed about them here. Now what is the need of removing admin menus? It entirely depends on the user, everyday many searches are made on removing unwanted menus from WordPress dashboard.
For Example:
Suppose you designing a static website for your client. A static website simply means a site having few static pages like Press, Contact, About, Links, Projects etc. In general it doesn’t contains any dynamic content types like posts etc. Here comes the need of removing post menu from admin area so that your client won’t get confused with the term ‘Posts’ while managing or updating his website.
So for removing the post menu, all you have to do is open your theme’s function.php file and add the following code there:
add_action( ‘admin_menu’, ‘my_remove_menu_pages’ );
function my_remove_menu_pages() {
remove_menu_page(‘edit.php’);
}
In the above code we have use edit.php as the post slug, the reason is that Dashboard -> Posts link is yourdomain.com/wp-admin/edit.php.
Similarly we can use other menu slugs in the above code for removing admin menus.
This is what you need: <?php remove_menu_page( $menu_slug ) ?>
You can use it by replacing the menu slug with the name of the .php page for the menu item which you want to remove (as shown in the above example).
Now let us take another example of ‘Tools’ menu:
Again you can use the same code replacing posts menu slug (edit.php) with the tools menu slug i.e. tools.php
add_action( ‘admin_menu’, ‘my_remove_menu_pages’ );
function my_remove_menu_pages() {
remove_menu_page(‘tools.php’);
}
Is it possible to remove multiple menu items with one hack?
Yes you can remove multiple menu items with one block of code. Following example shows how we have removed both tools and posts admin menus:
add_action( ‘admin_menu’, ‘my_remove_menu_pages’ );
function my_remove_menu_pages() {
remove_menu_page(‘edit.php’);
remove_menu_page(‘tools.php’);
}
In the above code we have just combined remove_menu_page(‘edit.php’); andremove_menu_page(‘tools.php’); lines from the first & second examples. You can expand the code to multiple lines and remove admin menu items.
How to find menu slug to use in the above code?
As you know, for removing a menu item what all you need is above code and the menu slug. Now for finding the right menu slug simply visit your admin area dashboard, put your mouse over the menu item and notice its link. The last slug after wp-admin/ is your menu slug which you can use for removing a particular admin menu item.
For Example:
Let us move back to our first example. In the first example we have used remove_menu_page(‘edit.php’);
The reason is posts menu link is yourdomain.com/wp-admin/edit.php where edit.php is the menu slug.
Whereas in-case of tools menu, the slug is tools.php because its menu URL is yourdomain.com/wp-admin/tools.php.