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

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.

Top ↑


$path string Optional
Path relative to the home URL.

Default: ''

$scheme string|null Optional
Scheme to give the home URL context. Accepts 'http', 'https', 'relative', 'rest', or null.

Default: null

Top ↑


string Home URL link with optional path appended.

Top ↑


File: wp-includes/link-template.php. View all references

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

Top ↑


Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex


    $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.