I am trying to hide almost every single admin menu from wordpress dashboard for a specific user id who has administrator role. I want to give that user only option to edit a certain custom post type named lessons and other custom post type Events.

I am using LMS wordpress theme from themeforest by designthemes. I am not sure why this theme just don't give access to the WP-admin for other role except administrator, like Editor, Contributor etc. So I decided to give that specific user administrator role so that he can get in to wordpress dashboard. Then my plan is just to hide other admin menu for this user.

I have used the plugin called User role editor pro and other free plugins. but nothing seems to be working with this. Then I tried with the below code. But this code is removing these admin menus from other administrator dashboard as well where I want these menus to be removed for this user id only who's user id is 279 here. Any help is appreciated. This is the site link https://impactmarketingsystems.com/

function hide_menu(){
 global $current_user;
 $user_id = get_current_user_id();
 // echo "user:".$user_id;   // Use this to find your user id quickly

    if($user_id != '279'){

        // To remove the whole Appearance admin menu you would use;

        remove_menu_page( 'themes.php' );

        // To remove the theme editor and theme options submenus from
        // the Appearance admin menu, as well as the main 'Themes'
        // submenu you would use 

        remove_menu_page( 'index.php' );
        remove_submenu_page( 'index.php', 'update-core.php' );

        remove_submenu_page( 'themes.php', 'themes.php' );
        remove_submenu_page( 'themes.php', 'theme-editor.php' );
        remove_submenu_page( 'themes.php', 'theme_options' );

        remove_menu_page( 'users.php' );
        remove_submenu_page( 'users.php', 'user-new.php' );
        remove_submenu_page( 'users.php', 'profile.php' );

        remove_menu_page( 'upload.php' );
        remove_submenu_page( 'upload.php', 'media-new.php' );
        remove_submenu_page( 'upload.php', 'upload.php?page=wp-smush-bulk' );

        remove_menu_page( 'admin.php?page=Wordfence' );
        remove_submenu_page( 'admin.php?page=Wordfence', 'media-new.php' );

        remove_menu_page( 'edit.php?post_type=dt_teachers' );
        remove_submenu_page( 'edit.php?post_type=dt_teachers', 'post-new.php?post_type=dt_teachers' );

        remove_menu_page( 'edit.php?post_type=dt_portfolios' );
        remove_submenu_page( 'edit.php?post_type=dt_portfolios', 'post-new.php?post_type=dt_portfolios' );
        remove_submenu_page( 'edit-tags.php?taxonomy=portfolio_entries', 'edit-tags.php?taxonomy=portfolio_entries&post_type=dt_portfolios' );

        remove_menu_page( 'edit.php' );
        remove_submenu_page( 'edit.php', 'post-new.php' );
        remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=category' );
        remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=post_tag' );

        // Remove Page menu Items
        remove_menu_page( 'edit.php?post_type=page' );
        remove_submenu_page( 'edit.php?post_type=page', 'post-new.php?post_type=page' );

        // Remove Comments Menu

        remove_menu_page( 'edit-comments.php' );

        //// Remove LMS Menu
        remove_menu_page( 'admin.php?page=parent' );

         remove_menu_page( 'tools.php' );                  //Tools
         remove_menu_page( 'options-general.php' );        //Settings

          remove_menu_page( 'plugins.php' );        //Plugins

          remove_menu_page( 'edit.php?post_type=product' );

// Not working
// Remove WP Contacts Items  
        remove_menu_page( 'admin.php?page=shwcp_options' );
        remove_submenu_page( 'admin.php?page=shwcp_options', 'admin.php?page=shwcp_options&db=1' );
        remove_submenu_page( 'admin.php?page=shwcp_options', 'admin.php?page=shwcp_add_db' );
        remove_submenu_page( 'admin.php?page=shwcp_options', 'admin.php?page=shwcp_delete_db' );    

        remove_menu_page( 'admin.php?page=upme-settings' ); 

        remove_menu_page( 'admin.php?page=ultimate_affiliates_pro' );     


add_action('admin_head', 'hide_menu');


problem is with your logical statement. now you are trying to remove dashboard staff where user id is not '279', which means only user id 279 can see dashboard. you can try this in if statement

if(is_admin() && $user_id == '279'){ //your codes }
  • Thanks bro. I was so stupid that I couldn't found this simple logic. Previously I tried using ! and without ! but that didn't work. So I was confused. But thanks for your help. This worked – Md. Amanur Rahman Nov 25 '17 at 10:54
  • My pleasure bro! – Kanon Chowdhury Nov 25 '17 at 18:11

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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