wppaste
WordPress

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.

Retrieves the URL to the admin area for the network.

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.

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.

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?

The function checks is_multisite() first and, when it returns false, calls admin_url() directly and returns without ever building the network path. This is expected on a single-site install; the network admin only exists once multisite is enabled.

Do I need to escape the return value before printing it?

Yes. The final URL passes through the network_admin_url filter, so any plugin can change it, and the raw string is not guaranteed to be output-safe HTML.

Does it matter if I pass 'sites.php' or '/sites.php' as $path?

No. When $path is a non-empty string it is stripped of a leading slash with ltrim() before being appended to the base network admin URL, so both forms produce the same result.

What does the scheme argument actually control?

The 'admin' scheme (the default) obeys force_ssl_admin() and is_ssl(), while explicitly passing 'http' or 'https' overrides that logic and hardcodes the scheme in the generated URL, which is useful for links sent outside the current request such as in emails.

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

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
10–25

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 30.

Plugin surface
1 hook

Third-party callbacks on 'network_admin_url' run inside this call, and their cost is not bounded by anything here.

Called by
38

38 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
!is_multisite()10is_multisite(), admin_url()
is_multisite()18–20is_multisite(), network_site_url(), apply_filters()
is_multisite() && is_string($path)25is_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:

  1. apply_filters( network_admin_url )filterline 3853 (+23 into the body)

    Filters the network admin URL.

Uses · 4

Used by · 38

Show all 38

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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.