get_site_url

Retrieves the URL for a given site where WordPress application files (e.g.

Description

(string) get_site_url( (constant) $blog_id = null, (string) $path = '', (null) $scheme = null ); 

wp-blog-header.php or the wp-admin/ folder) are accessible.

Returns the site_url option 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 (3)

0. $blog_id — Optional. (constant) => null
Site ID. Default null (current site).
1. $path — Optional. (string) => ''
Path relative to the site URL. Default empty.
2. $scheme — Optional. (null) => null
Scheme to give the site URL context. Accepts http,, https., login, login_post, admin, or relative. Default null.

Usage

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

Defined (1)

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

/wp-includes/link-template.php  
  1. function get_site_url( $blog_id = null, $path = '', $scheme = null ) { 
  2. if ( empty( $blog_id ) || !is_multisite() ) { 
  3. $url = get_option( 'siteurl' ); 
  4. } else { 
  5. switch_to_blog( $blog_id ); 
  6. $url = get_option( 'siteurl' ); 
  7.  
  8. $url = set_url_scheme( $url, $scheme ); 
  9.  
  10. if ( $path && is_string( $path ) ) 
  11. $url .= '/' . ltrim( $path, '/' ); 
  12.  
  13. /** 
  14. * Filters the site URL. 
  15. * @since 2.7.0 
  16. * @param string $url The complete site URL including scheme and path. 
  17. * @param string $path Path relative to the site URL. Blank string if no path is specified. 
  18. * @param string|null $scheme Scheme to give the site URL context. Accepts 'http', 'https', 'login',  
  19. * 'login_post', 'admin', 'relative' or null. 
  20. * @param int|null $blog_id Site ID, or null for the current site. 
  21. */ 
  22. return apply_filters( 'site_url', $url, $path, $scheme, $blog_id );