network_site_url

Retrieves the site URL for the current network.

Description

(string) network_site_url( (string) $path = '', (null) $scheme = null ); 

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

Returns (string)

Site URL link with optional path appended.

Parameters (2)

0. $path — Optional. (string) => ''
Path relative to the site URL. Default empty.
1. $scheme — Optional. (null) => null
Scheme to give the site URL context. Accepts http,, https., or relative. Default null.

Usage

  1. if ( !function_exists( 'network_site_url' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // Optional. Path relative to the site URL. Default empty. 
  5. $path = ''; 
  6.  
  7. // Optional. Scheme to give the site URL context. Accepts 
  8. // 'http', 'https', or 'relative'. Default null. 
  9. $scheme = null; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = network_site_url($path, $scheme); 
  13.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/link-template.php  
  1. function network_site_url( $path = '', $scheme = null ) { 
  2. if ( ! is_multisite() ) 
  3. return site_url($path, $scheme); 
  4.  
  5. $current_network = get_network(); 
  6.  
  7. if ( 'relative' == $scheme ) 
  8. $url = $current_network->path; 
  9. else 
  10. $url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme ); 
  11.  
  12. if ( $path && is_string( $path ) ) 
  13. $url .= ltrim( $path, '/' ); 
  14.  
  15. /** 
  16. * Filters the network site URL. 
  17. * @since 3.0.0 
  18. * @param string $url The complete network site URL including scheme and path. 
  19. * @param string $path Path relative to the network site URL. Blank string if 
  20. * no path is specified. 
  21. * @param string|null $scheme Scheme to give the URL context. Accepts 'http', 'https',  
  22. * 'relative' or null. 
  23. */ 
  24. return apply_filters( 'network_site_url', $url, $path, $scheme );