WordPress Multisite admin cleanup snippets

Snippets to remove unnecessary admin bar links and admin sidebar links.

Cleanup of admin sidebar:

The following snippet removes menu item Dashboard.
This also removes access to menu items for update core and upgrade network.
As a solution we add new menu items as sub items to settings menu, providing easy access to these two sites.

/*
 * Customizing the network admin sidebar. 
 * Removes link to dashboard. Adds link to updates and upgrade network as settings submenu item
*/
function maksimer_customize_network_sidebar_menu() {
	remove_menu_page( 'index.php' );
	add_submenu_page( 'settings.php', __( 'Updates' ), __( 'Updates' ), 'manage_options', 'update-core.php' );
	add_submenu_page( 'settings.php', __( 'Upgrade Network' ), __( 'Upgrade Network' ), 'manage_options', 'upgrade.php' );
}
add_action('network_admin_menu', 'maksimer_customize_network_sidebar_menu');

Cleanup of admin bar:

This snippet removes the following links from admin bar (top bar):

  • My sites –> Network Admin –> Dashboard
  • Edit site link (Backend)
  • All sub menu items from My sites –> Site name
/*
 * Manage the admin bar
*/
function maksimer_network_admin_bar() {
	global $wp_admin_bar;
	$wp_admin_bar->remove_menu( 'network-admin-d' );
	$wp_admin_bar->remove_menu( 'edit-site' );

	// Array of blogs in network
	$network_blogs = wp_get_sites();
	foreach ( $network_blogs as $network_blog ) {
		// Get blog id from array
		$network_blog_id = $network_blog['blog_id'];

		$wp_admin_bar->remove_menu( 'blog-'.$network_blog_id.'-d' ); // Dashboard
		$wp_admin_bar->remove_menu( 'blog-'.$network_blog_id.'-c' ); // Manage Comments
		$wp_admin_bar->remove_menu( 'blog-'.$network_blog_id.'-v' ); // View Site
		$wp_admin_bar->remove_menu( 'blog-'.$network_blog_id.'-n' ); // New post
	}
}
add_action( 'wp_before_admin_bar_render', 'maksimer_network_admin_bar' );

Leave a Reply

Your email address will not be published. Required fields are marked *