network_admin_url( string $path = '', string $scheme = 'admin' ): string
- Since
- 3.0.0
- Source
wp-includes/link-template.php:3830
Builds a URL pointing at a page in the network admin, using admin_url() as a fallback whenever the current install is not a multisite network. Reach for it when a plugin or theme needs a link into wp-admin/network/ (site management, network settings, network plugin or theme screens) rather than the current site's own dashboard. Wrap the return value in esc_url() before echoing it in HTML, since the network_admin_url filter can alter it.
Compatibility
- WordPress
- since 3.0.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$pathstringoptional- Optional path relative to the admin URL. Default empty.Default:
'' $schemestringoptional- The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes.Default:
'admin'
Return value
string- Admin URL link with optional path appended.
Code examples
Every example is editable and runs in a real WordPress booted in your browser by WordPress Playground. Press Run, then edit the code: clicking away re-runs it. Nothing is sent anywhere until you do.
Link to the network Sites screen from an admin notice
A plugin wants to point a network administrator at the multisite Sites list from a dashboard notice.
$sites_url = network_admin_url( 'sites.php' );
printf(
'<p>Manage all network sites here: <a href="%s">%s</a></p>',
esc_url( $sites_url ),
esc_html( $sites_url )
);On a single-site install this simply falls back to admin_url( 'sites.php' ), which does not exist as a real screen there, so gate this kind of link behind is_multisite() in real plugin code.
Force https for a network admin link sent in an email
A notification email should always point to an https network admin URL regardless of the site's normal admin scheme.
$plugins_url = network_admin_url( 'plugins.php', 'https' );
echo esc_html( 'Update link for the email body: ' . $plugins_url );Common problems and fixes · 4
- Why does network_admin_url() give me a normal admin_url instead of a wp-admin/network/ URL?
- Do I need to escape the return value before printing it?
- Does it matter if I pass 'sites.php' or '/sites.php' as $path?
- What does the scheme argument actually control?
Why does network_admin_url() give me a normal admin_url instead of a wp-admin/network/ URL?
Do I need to escape the return value before printing it?
Does it matter if I pass 'sites.php' or '/sites.php' as $path?
What does the scheme argument actually control?
Alternatives and related functions
admin_url- When the link should point at the current site's own dashboard rather than the network-wide admin, or when the install may not be multisite at all.
self_admin_url- When code runs in both site and network admin contexts and the link should follow whichever admin the current request is already in.
network_site_url- When linking to a front-end network URL (not an admin screen) such as the network's main site address.
get_admin_url- When the target is a specific site's admin area by blog ID inside a multisite network, rather than the shared network admin.
Performance profile
How much work a call to network_admin_url() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 10–25
- Plugin surface
- 1 hook
- Called by
- 38
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 30.
Third-party callbacks on 'network_admin_url' run inside this call, and their cost is not bounded by anything here.
38 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost network_admin_url() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_multisite() | 10 | is_multisite(), admin_url() |
is_multisite() | 18–20 | is_multisite(), network_site_url(), apply_filters() |
is_multisite() && is_string($path) | 25 | is_multisite(), network_site_url(), ltrim(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 30 instructions, 10–25 executed per call, 3 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while network_admin_url() runs, in this order:
Uses · 4
- is_multisite()Determines whether Multisite is enabled.
- admin_url()Retrieves the URL to the admin area for the current site.
- network_site_url()Retrieves the site URL for the current network.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 38
- WP_Automatic_Updater::send_email()Sends an email upon the completion or failure of a background core update.
- WP_Customize_Manager::handle_load_themes_request()Loads themes into the theme browsing/installation UI.
- WP_MS_Sites_List_Table::column_blogname()Handles the site name column output.
- WP_MS_Sites_List_Table::column_users()Handles the users column output.
- WP_MS_Sites_List_Table::handle_row_actions()Generates and displays row action links.
- WP_MS_Users_List_Table::column_blogs()Handles the sites column output.
- WP_MS_Users_List_Table::get_views()
- WP_MS_Users_List_Table::handle_row_actions()Generates and displays row action links.
- WP_Plugin_Dependencies::check_plugin_dependencies_during_ajax()Checks plugin dependencies after a plugin is installed via AJAX.
- WP_Plugin_Dependencies::display_admin_notice_for_unmet_dependencies()Displays an admin notice if dependencies are not installed.
- WP_Plugin_Install_List_Table::get_more_details_link()Creates a 'More details' link for the plugin.
- WP_Plugins_List_Table::get_view_details_link()Returns a 'View details' link for the plugin.
Show all 38
- WP_Plugins_List_Table::single_row()Generates the markup for a single plugin row.
- WP_Site_Health::get_test_plugin_version()Tests if plugins are outdated, or unnecessary.
- WP_Themes_List_Table::no_items()
- core_update_footer()Returns core update footer message.
- get_edit_profile_url()Retrieves the URL to the user's profile editor.
- get_site_screen_help_tab_args()Returns the arguments for the help tab on the Edit Site screens.
- network_edit_site_nav()Outputs the HTML for a network's "Edit Site" tabular interface.
- newblog_notify_siteadmin()Notifies the network admin that a new site has been activated.
- newuser_notify_siteadmin()Notifies the network admin that a new user has been activated.
- self_admin_url()Retrieves the URL to the admin area for either the current site or the network depending on context.
- site_admin_notice()Displays an admin notice to upgrade all sites after a core upgrade.
- update_nag()Returns core update notification message.
- update_network_option_new_admin_email()Sends a confirmation request email when a change of network admin email address is attempted.
- update_right_now_message()Displays WordPress version and active theme in the 'At a Glance' dashboard widget.
- validate_plugin_requirements()Validates the plugin requirements for WordPress version and PHP version.
- wp_admin_bar_my_sites_menu()Adds the "My Sites/[Site Name]" menu and all submenus.
- wp_admin_bar_new_content_menu()Adds "Add New" menu.
- wp_admin_bar_site_menu()Adds the "Site Name" menu.
- wp_admin_bar_updates_menu()Provides an update link if theme/plugin/core updates are available.
- wp_ajax_install_plugin()Handles installing a plugin via AJAX.
- wp_ajax_install_theme()Handles installing a theme via AJAX.
- wp_ajax_query_themes()Handles getting themes from themes_api() via AJAX.
- wp_ajax_search_install_plugins()Handles searching plugins to install via AJAX.
- wp_ajax_search_plugins()Handles searching plugins via AJAX.
- wp_get_plugin_action_button()Gets the markup for the plugin install action button.
- wp_network_dashboard_right_now()
Source code
function network_admin_url( $path = '', $scheme = 'admin' ) { if ( ! is_multisite() ) { return admin_url( $path, $scheme ); } $url = network_site_url( 'wp-admin/network/', $scheme ); if ( $path && is_string( $path ) ) { $url .= ltrim( $path, '/' ); } /** * Filters the network admin URL. * * @since 3.0.0 * @since 5.8.0 The `$scheme` parameter was added. * * @param string $url The complete network admin URL including scheme and path. * @param string $path Path relative to the network admin URL. Blank string if * no path is specified. * @param string|null $scheme The scheme to use. Accepts 'http', 'https', * 'admin', or null. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). */ return apply_filters( 'network_admin_url', $url, $path, $scheme );}Changelog
Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/link-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.