Wednesday 3 February 2016

How to Remove Menu Item in WordPress Admin Panel

Have you ever worked with a client who has a hard time understanding technology? Well, as a consultant, designer, or developer, it is your job to make things easier for them. WordPress admin panel comes with a lot of options in the menu, but you can get rid of them fairly easily if necessary. With one of our clients, we needed to get rid of few menu items, so it is easier for her to understand things. In this article, we will show you how easy it is to remove a menu item in the WordPress Admin Panel.
For WordPress 3.1 or above, just paste the following code in your theme’s functions.php file:
1add_action( 'admin_menu''my_remove_menu_pages' );
2function my_remove_menu_pages() {
3    remove_menu_page('link-manager.php');  
4}
In version prior to WordPress 3.1, you would need to paste the following code in your theme’s functions.php file:
01function remove_menus () {
02global $menu;
03    $restricted array(__('Links'));
04    end ($menu);
05    while (prev($menu)){
06        $value explode(' ',$menu[key($menu)][0]);
07        if(in_array($value[0] != NULL?$value[0]:"" ,$restricted)){unset($menu[key($menu)]);}
08    }
09}
10add_action('admin_menu''remove_menus');
The code above will get rid of the Links option for all users (including administrators). Only two user roles are allowed to see the Link tab (Administrators and Editors). Now if this is for a multi-author site (where there are many editors), and you as an administrator still want access to the Links menu, then you can add parameters to do so.
You would need to utilize the function current_user_can(), and with a simple if statement, you can get rid of the link menu or other items for specific user role.
This is a very handy trick for consultants and developers who work on larger sites.
Refrence from

No comments:

Post a Comment