network_home_url()

 

File: wp-includes/link-template.php

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' ) ) ) {
		$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 );
	}

	if ( $path && is_string( $path ) ) {
		$url .= ltrim( $path, '/' );
	}

	/**
	 * Filters the network home URL.
	 *
	 * @since 3.0.0
	 *
	 * @param string      $url         The complete network home URL including scheme and path.
	 * @param string      $path        Path relative to the network home URL. Blank string
	 *                                 if no path is specified.
	 * @param string|null $orig_scheme Scheme to give the URL context. Accepts 'http', 'https',
	 *                                 'relative' or null.
	 */
	return apply_filters( 'network_home_url', $url, $path, $orig_scheme );
}

参数:network_home_url( string $path = '', string $scheme = null )

返回带有适当协议的主URL,否则‘HTTPS’是_ssl()和‘HTTP’。如果$scheme是‘HTTP’或‘HTTPS’,则会覆盖is_ssl()。

Path relative to the home URL. Scheme to give the home URL context. Accepts 'http', 'https', or 'relative'.

(字符串)附加了可选路径的主URL链接。

$path

(string)
(Optional)
Path relative to the home URL.

Default value: ''

$scheme

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

Default value: null

{acontent3}

  1. Basic Example

    $url = network_home_url();
    echo $url;
    

    Output: http://www.example.com

    Note the lack of a trailing slash.

You must log in before being able to contribute a note or feedback.

44.44% (4) 次Baidu访问
11.11% (1) 次Google访问
44.44% (4) 次Sogou访问
  • 蜘蛛:Baidu,4次,更新时间:2019-04-25 14:13:30
  • 蜘蛛:Google,1次,更新时间:2019-05-13 04:01:15
  • 蜘蛛:Sogou,4次,更新时间:2019-05-05 15:02:47

参与评论