So I've got this code which does the reverse of what I want it to do.

add_action('admin_menu', 'remove_admin_menu_links');
function remove_admin_menu_links(){
    $user = wp_get_current_user();
    //if( $user && isset($user->user_email) && 'user@email.com' == $user->user_email ) {
    if( !$user && isset($user->user_login) && 'USERNAMEHERE'  == $user->user_login ) {
    remove_menu_page( 'edit.php?post_type=page' ); 
    remove_menu_page( 'edit.php?post_type=videos' );
    remove_menu_page( 'edit.php' );


remove_theme_support( 'user-admin-menu' );

So the above code hides admin menu's if the username is "USERNAMEHERE", however id like it to do the complete opposite, so id like all menu's to be hidden to all admins apart from a certain username.

I thought adding ! inside the if statement might have done it but it doesnt seem to work ?

    function hide_menu() {
    global $current_user;
    $current_user = wp_get_current_user();
    $user_name = $current_user->user_login; 

        //check condition for the user means show menu for this user
        if(is_admin() &&  $user_name != 'USERNAME') {

        //your code here
add_action('admin_head', 'hide_menu');
| improve this answer | |
  • Unfortunately doesnt work – Randomer11 Nov 15 '18 at 12:01
  • Please check I edited above script. Hope this works for you. – vikrant zilpe Nov 15 '18 at 12:42
  • unfortunately not, it removes the menu for all admins including the username stated – Randomer11 Nov 15 '18 at 12:49
  • I've edited your code, ive made a couple of changes changing "user_firstname to user login and that works, now ive got to figure out how to hide the customiser and theme options menus :) – Randomer11 Nov 15 '18 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.