network_home_url

Retrieves the home URL for the current network.

Description

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

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

Returns (string)

Home URL link with optional path appended.

Parameters (2)

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

Usage

  1. if ( !function_exists( 'network_home_url' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // Optional. Path relative to the home URL. Default empty. 
  5. $path = ''; 
  6.  
  7. // Optional. Scheme to give the home 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_home_url($path, $scheme); 
  13.  

Defined (1)

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

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