This is how you can remove the WordPress Admin bar (aka Toolbar) only on some sites of a WordPress multisite network.
The following example will remove the WordPress Toolbar, only for non-administrator’s, and only the main site of the multisite network:
/* * Removes the Admin Bar, only for non-administrators, and ONLY * on the main site of the multisite network. */ $bi = get_current_blog_id(); if ( is_user_logged_in() && ! current_user_can( 'manage_options' ) && 1 === $bi ) { show_admin_bar( false ); }
The following example is the same as above, but it will also remove the Toolbar for administrators:
/* * Removes the Admin Bar, only for non-administrators, and ONLY * on the main site of the multisite network. */ $bi = get_current_blog_id(); if ( 1 === $bi ) { show_admin_bar( false ); }
You can also choose which sites in the multisite network will be affected by this code.
The following code will remove the Toolbar, only for non-administrator’s, and only on 2 specified sites of the multisite network (blog ids 3 and 5 in this example). You must replace the “3, 5” on line 7 with a comma-separated list of your own blog IDs. These are the blog IDs that you want to be affected this code.
/* * Removes the Admin Bar ONLY for non-admins and only * on 2 specific sites in the multisite network. */ $bi = get_current_blog_id(); if ( is_user_logged_in() && ! current_user_can( 'manage_options' ) && in_array( $bi, array(3, 5) ) ) { // Use your own blog IDs here show_admin_bar( false ); }
Thomas Schwinn
January 24th, 2021 at 10:04 am
where exactly do I put this code? in the functions.php? if yes, in which one?
Isabel
January 28th, 2021 at 10:15 pm
Yes, please see how to add PHP code to your WordPress site.