• In a multisite environment.

    I want to remove the “Change Themes” functionality from the customizer for site admins (not necessarily super admins).

    I’ve been told that the best way the best way to achieve that is to remove the “change themes” capability from the site admin role.

    I know there is the Role Editor plugin but seems overkill to use a plugin for something this specific.

    Can anyone advise on a code snippet to remove the “change themes” capability for all roles below super admin?

Viewing 1 replies (of 1 total)
  • Hi @twd

    You could use the built in WordPress function remove_submenu_page in a function which checked for a specific user ID. You would hook that to admin_head.

    
    <?php
    
    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 != '1') {
    
            // 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_submenu_page( 'themes.php', 'themes.php' );
            remove_submenu_page( 'themes.php', 'theme-editor.php' );
            remove_submenu_page( 'themes.php', 'theme_options' );
    
        }
    }
    
    add_action('admin_head', 'hide_menu');
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘How to remove admin capability to switch themes’ is closed to new replies.