network_home_url

Advertisement

Summery Summery

Retrieves the home URL for the current network.

Syntax Syntax

network_home_url( string $path = '', string $scheme = null )

Description Description

Returns the home URL with the appropriate protocol, ‘https’ is_ssl() and ‘http’ otherwise. If $scheme is ‘http’ or ‘https’, is_ssl() is overridden.

Parameters Parameters

$path

(Optional) Path relative to the home URL.

Default value: ''

$scheme

(Optional) Scheme to give the home URL context. Accepts 'http', 'https', or 'relative'.

Default value: null

Return Return

(string) Home URL link with optional path appended.

Source Source

File: wp-includes/link-template.php

	 *                            'relative' or null.
	 */
	return apply_filters( 'network_site_url', $url, $path, $scheme );
}

/**
 * Retrieves the home URL for the current network.
 *
 * Returns the home URL with the appropriate protocol, 'https' is_ssl()
 * and 'http' otherwise. If `$scheme` is 'http' or 'https', `is_ssl()` is
 * overridden.
 *
 * @since 3.0.0
 *
 * @param string $path   Optional. Path relative to the home URL. Default empty.
 * @param string $scheme Optional. Scheme to give the home URL context. Accepts
 *                       'http', 'https', or 'relative'. Default null.
 * @return string Home URL link with optional path appended.
 */
function network_home_url( $path = '', $scheme = null ) {
	if ( ! is_multisite() ) {
		return home_url( $path, $scheme );
	}

	$current_network = get_network();
	$orig_scheme     = $scheme;

	if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) {
		$scheme = is_ssl() && ! is_admin() ? 'https' : 'http';
	}

	if ( 'relative' === $scheme ) {
		$url = $current_network->path;
	} else {
		$url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme );

Advertisement

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.

Advertisement

Leave a Reply