home_url( string $path = , string|null $scheme = null ): string

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

Description

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.

Parameters

$pathstringoptional
Path relative to the home URL.

Default:''

$schemestring|nulloptional
Scheme to give the home URL context. Accepts 'http', 'https', 'relative', 'rest', or null.

Default:null

Return

string Home URL link with optional path appended.

Source

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

Changelog

VersionDescription
3.0.0Introduced.

User Contributed Notes

  1. Skip to note 3 content

    Example

    $url = home_url();
    echo $url;

    Output: http://www.example.com

    (Note the lack of a trailing slash)

    $url = home_url( '/' );
    echo $url;

    Output: http://www.example.com/

    $url = home_url( $path = '/', $scheme = 'https' );
    echo $url;

    Output: https://www.example.com/

    $url = home_url( $path = 'example', $scheme = 'relative' );
    echo $url;

    Output: /example

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