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

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

Description 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 Parameters


(string) (Optional) Path relative to the home URL.

Default value: ''


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

Default value: null

Top ↑

Return Return

(string) Home URL link with optional path appended.

Top ↑

Source Source

File: wp-includes/link-template.php

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

Top ↑

Changelog Changelog

Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes 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.