WordPress get_home_url() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Returns a URL

Definition

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.

Syntax

Return the URL, then print it with esc_url().

WordPress
<?php echo esc_url( get_home_url() ); ?>
CallWhat 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().

Full declaration
WordPress
get_home_url( int|null $blog_id = null, string $path = '', string|null $scheme = null ): string

Parameters

ParameterDescription
$blog_idint|null. Site ID on a multisite. Default is null, the current site.
$pathstring. A path to add after the home URL, such as /contact/.
$schemestring|null. http, https, or relative. Default is null, which follows the current page.

Return Value

Return ValueDescription
stringThe home URL, with the path added when you pass one. It has no trailing slash unless your path adds it.

WordPress Examples

Three short examples. Each one shows the code and what it prints or does.

Example 1 — Print the home URL

The simplest call.

WordPress
<?php
echo esc_url( get_home_url() );

How It Works

  1. get_home_url() returns the front page address.
  2. esc_url() makes it safe for HTML.
  3. There is no slash at the end.

Example 2 — Add a path

Pass a path as the second argument to link to a page.

WordPress
<?php
echo esc_url( get_home_url( null, '/contact/' ) );

How It Works

  1. null means the current site.
  2. /contact/ is added after the home URL.
  3. You can build menu or button links this way.

Example 3 — Get a relative URL

Use the relative scheme to drop the domain.

WordPress
<?php
echo esc_url( get_home_url( null, '/about/', 'relative' ) );

How It Works

  1. relative returns only the path part.
  2. It is handy for links that must work on any domain.
  3. Use https as the scheme to force a secure URL instead.

Frequently Asked Questions

It returns the home URL of a site. That is the address of your front page.
get_home_url() lets you choose a site on multisite. home_url() is a shortcut for the current site.
Home URL is the front of your site. Site URL is where WordPress files are installed. They are often the same, but not always.
No. It returns a string. Use echo with esc_url() to print it.
It sets http, https, or relative. If you leave it empty, WordPress follows the current page.

Next: get_page_link()

Return the permalink of a page.

get_page_link() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful