home_url()WP 3.0.0

Retrieves the URL for the current site where the front end is accessible.

Returns the 'home' option with the appropriate protocol. The protocol will be 'https' if is_ssl() evaluates to true; otherwise, it will be the same as the 'home' option. If $scheme is 'http' or 'https', is_ssl() is overridden.

1 time — 0.000047 sec (very fast) | 50000 times — 0.51 sec (very fast) | PHP 7.1.2, WP 4.7.3

No Hooks.


String. Home URL link with optional path appended.


home_url( $path, $scheme );
Path relative to the home URL.
Default: ''
Scheme to give the home URL context. Accepts 'http', 'https', 'relative', 'rest', or null.
Default: null



#1 Examples of obtaining a website address:

echo home_url();                       // http://example.com

echo home_url('/');                    // http://example.com/

echo home_url( 'blog', 'relative' );   // /blog

echo home_url( 'blog' );               // https://example.com/blog

echo home_url( '/blog', 'https' );     // https://example.com/blog

echo home_url( '#hash', 'https' );     // https://example.com/#hash

echo home_url( '//foo.bar/foo' );      // http://example.com/foo.bar/foo

echo home_url( 'http://foo.bar/foo' ); // http://example.com/http://foo.bar/foo

echo home_url( '/mypage?id=123' );     // https://example.com/mypage?id=123

#2 If WP core is installed to sub directory wp

echo home_url(); // https://example.com
echo site_url(); // https://example.com/wp


Since 3.0.0 Introduced.

home_url() code WP 6.5.2

function home_url( $path = '', $scheme = null ) {
	return get_home_url( null, $path, $scheme );