Using WordPress ‘network_admin_url’ PHP filter

The network_admin_url filter allows you to modify the network admin URL in a WordPress multisite installation.

Usage

add_filter('network_admin_url', 'your_custom_function', 10, 3);

function your_custom_function($url, $path, $scheme) {
    // Your custom code here

    return $url;
}

Parameters

  • $url (string) – The complete network admin URL including scheme and path.
  • $path (string) – Path relative to the network admin URL. Empty string if no path is specified.
  • $scheme (string|null) – The scheme to use. Accepts ‘http’, ‘https’, ‘admin’, or null. Default is ‘admin’, which obeys force_ssl_admin() and is_ssl().

Examples

Add a query parameter to the network admin URL

add_filter('network_admin_url', 'add_query_param', 10, 3);

function add_query_param($url, $path, $scheme) {
    $url = add_query_arg('custom_param', 'value', $url);

    return $url;
}

This example adds a custom query parameter ‘custom_param’ with the value ‘value’ to the network admin URL.

Force HTTPS scheme for the network admin URL

add_filter('network_admin_url', 'force_https_scheme', 10, 3);

function force_https_scheme($url, $path, $scheme) {
    $url = set_url_scheme($url, 'https');

    return $url;
}

This example forces the HTTPS scheme for the network admin URL.

Modify the network admin URL path

add_filter('network_admin_url', 'modify_url_path', 10, 3);

function modify_url_path($url, $path, $scheme) {
    $url = str_replace('wp-admin/network/', 'custom-path/', $url);

    return $url;
}

This example replaces the ‘wp-admin/network/’ path segment with ‘custom-path/’ in the network admin URL.

Add a subdomain to the network admin URL

add_filter('network_admin_url', 'add_subdomain', 10, 3);

function add_subdomain($url, $path, $scheme) {
    $url = str_replace('://', '://admin.', $url);

    return $url;
}

This example adds an ‘admin’ subdomain to the network admin URL.

Change the network admin URL domain

add_filter('network_admin_url', 'change_domain', 10, 3);

function change_domain($url, $path, $scheme) {
    $url = str_replace('example.com', 'example.org', $url);

    return $url;
}

This example replaces the domain ‘example.com’ with ‘example.org’ in the network admin URL.