Hide an Admin Menu in WordPress

Have you ever needed to hide a specific admin menu from other users in WordPress? Maybe you want to hide the Plugins and Appearance menus to keep your users out of trouble. Just place the below code in your themes functions.php file to hide the Plugins menu from all users except for admin:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
add_action('admin_head', 'hide_menus');
 
function hide_menus() {
    global $current_user;
    get_currentuserinfo();
     
    If($current_user->user_login != 'admin') {
        ?>
        <style>
           #menu-plugins{
                display:none;
            }
        </style>
        <?php
    }
}
?>
As another example lets say we want to hide the Links menu from all users that aren’t administrators in WordPress. The below code would do just that:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
add_action('admin_head', 'hide_menus');
 
function hide_menus() {
    if ( !current_user_can('manage_options') ) {
        ?>
        <style>
           #menu-links{
                display:none;
            }
        </style>
        <?php
    }
}
?>
This is a pretty simple method of hiding menus in the WordPress admin dashboard. Enjoy!

No comments:

Post a Comment