I want to put a Tools menu item on the Network Admin dashboard
If you meant under the core top-level “Dashboard” menu as seen on the following screenshot, then you can use the network_admin_menu
hook along with add_submenu_page()
to add your menu item.
Or if you wanted a top-level menu like the following, then use the same hook as above, but use add_menu_page()
to add the menu, and then use add_submenu_page()
to add menu items (i.e. submenus) to that top-level menu.
Full Working Example
<?php
/**
* Plugin Name: WPSE 391799
* Description: Network Admin custom "Tools" menus
* Version: 1.0
*/
// Adds the custom Network Admin menus.
add_action( 'network_admin_menu', 'wpse_391799_add_network_admin_menus' );
function wpse_391799_add_network_admin_menus() {
add_submenu_page( 'index.php', // parent slug or file name of a standard WordPress admin page
'My Tools Page', // menu page title
'My Tools (Submenu)', // menu title
'manage_network', // user capability required to access the menu (and its page)
'my-tools-page', // menu slug that's used with the "page" query, e.g. ?page=menu-slug
'wpse_391799_render_tools_page' // the function which outputs the page content
);
add_menu_page( 'My Tools Page', // menu page title
'My Tools (Top-Level)', // menu title
'manage_network', // user capability required to access the menu (and its page)
'my-tools-page2', // menu slug to that's with the "page" query, e.g. ?page=menu-slug
'wpse_391799_render_tools_page', // the function which outputs the page content
'dashicons-admin-tools', // menu icon (in this case, I'm using a Dashicons icon's CSS class)
24 // menu position; 24 would place the menu above the "Settings" menu
);
add_submenu_page( 'my-tools-page2',
'My Tools Submenu Page',
'My Tools Submenu',
'manage_network',
'my-tools-submenu-page',
'wpse_391799_render_tools_submenu_page'
);
}
// Outputs the content for the "My Tools (Submenu)" and "My Tools (Top-Level)" pages.
function wpse_391799_render_tools_page() {
?>
<div class="wrap my-tools-parent">
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
<p>Foo bar. Bla bla. Your content here.</p>
</div>
<?php
}
// Outputs the content for the "My Tools Submenu" page.
function wpse_391799_render_tools_submenu_page() {
?>
<div class="wrap my-tools-submenu">
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
<p>Foo bar. Bla bla. Your content here.</p>
</div>
<?php
}