Example 1 — Print the home URL
The simplest call.
<?php
echo esc_url( get_home_url() ); How It Works
get_home_url()returns the front page address.esc_url()makes it safe for HTML.- There is no slash at the end.

In WordPress, get_home_url() returns the home URL of a site. This is the address visitors type to see your front page, for example https://example.com.
It works like home_url(), but it lets you pick a site on a multisite network with the first argument. On a normal site, home_url() is shorter and the same.
Return the URL, then print it with esc_url().
<?php echo esc_url( get_home_url() ); ?> | Call | What it does |
|---|---|
get_home_url() | The home URL of the current site. |
get_home_url( null, '/contact/' ) | The home URL plus a path. |
get_home_url( 2, '/', 'https' ) | The home URL of site 2, forced to use https. |
It returns a string. For the WordPress install address (where wp-admin lives) use get_site_url().
get_home_url( int|null $blog_id = null, string $path = '', string|null $scheme = null ): string | Parameter | Description |
|---|---|
$blog_id | int|null. Site ID on a multisite. Default is null, the current site. |
$path | string. A path to add after the home URL, such as /contact/. |
$scheme | string|null. http, https, or relative. Default is null, which follows the current page. |
| Return Value | Description |
|---|---|
| string | The home URL, with the path added when you pass one. It has no trailing slash unless your path adds it. |
Three short examples. Each one shows the code and what it prints or does.
The simplest call.
<?php
echo esc_url( get_home_url() ); get_home_url() returns the front page address.esc_url() makes it safe for HTML.Pass a path as the second argument to link to a page.
<?php
echo esc_url( get_home_url( null, '/contact/' ) ); null means the current site./contact/ is added after the home URL.Use the relative scheme to drop the domain.
<?php
echo esc_url( get_home_url( null, '/about/', 'relative' ) ); relative returns only the path part.https as the scheme to force a secure URL instead.Return the permalink of a page.
15 people found this page helpful