Add Custom Sub-Menu Links to Sites in the My Sites Menu in WordPress Multisite

The following snippet will add several links to the submenu for each site in the My Sites menu in WordPress Admin Dashboard. (Users, Themes, Plugins, Settings, & Tools)

Feel free to customize the code to your liking. Make note of the ‘id’ => ‘some_id’ as this must be unique.

Create a new plugin folder in WordPress, create a file inside that folder like nwd-custom-mysites-menu.php and add the following code to that file.

/**
 * Plugin Name: NWD Custom My Sites Menu
 * Description: Adds custom links to sites listed in the My Sites Menu. Must be network activated
 * Version: 0.0.1
 * Author: Mathew Moore
 * Plugin URI: https://nwdigital.cloud/plugins/nwd-my-sites-menu
 * Update URI: https://nwdigital.cloud/plugins/nwd-my-sites-menu/updates
 */

// Add submenu links to the sites under the "My Sites" admin navigation menu
function nwd_add_custom_links_to_my_sites_bar($admin_bar) {

	if ( function_exists( 'get_sites' ) && class_exists( 'WP_Site_Query' ) ) {
		$sites = get_sites();
		foreach ( $sites as $site ) {
			$menu_id = 'blog-' . $site->blog_id;

			switch_to_blog( $site->blog_id );
			$admin_url = admin_url();
			restore_current_blog();

			$admin_bar->add_node(
				array(
					'parent' => $menu_id,
					'id'     => $menu_id . '-users',
					'title'  => __( 'Users' ),
					'href'   => $admin_url . 'users.php',
				)
			);

			$admin_bar->add_node(
				array(
					'parent' => $menu_id,
					'id'     => $menu_id . '-themes',
					'title'  => __( 'Themes' ),
					'href'   => $admin_url . 'themes.php',
				)
			);

			$admin_bar->add_node(
				array(
					'parent' => $menu_id,
					'id'     => $menu_id . '-plugins',
					'title'  => __( 'Plugins' ),
					'href'   => $admin_url . 'plugins.php',
				)
			);

			$admin_bar->add_node(
				array(
					'parent' => $menu_id,
					'id'     => $menu_id . '-settings',
					'title'  => __( 'Settings' ),
					'href'   => $admin_url . 'options-general.php',
				)
			);

			$admin_bar->add_node(
				array(
					'parent' => $menu_id,
					'id'     => $menu_id . '-tools',
					'title'  => __( 'Tools' ),
					'href'   => $admin_url . 'tools.php',
				)
			);

			
		}
		return;
	}
}
add_action( 'admin_bar_menu', 'nwd_add_custom_links_to_my_sites_bar',999 );

Once you have completed the steps above, go to the WordPress Network Admin → Plugins and Network Activate this plugin.

Now you should see the menu items in the submenu of every site in your WordPress Multisite Netowork.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.