Remove WP Admin Bar For Non-Admins, on Select Sites in Multisite

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.

You can get your blog IDs in your WordPress dashboard –> “My Sites” –> “Network Admin” –> “Sites”. Click “Edit” under 1 of your sites. On the “Edit” page, look at the address bar. At the end of the URL, you’ll see “id=” and a number. That number will be the blog ID for that site in the multisite network.
/*
 * 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 );
}

See more: , ,

We've 2 Responses

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]