WordPress home_url() Function

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

Definition

In WordPress, home_url() returns the home URL of the current site. This is the address of your front page, such as https://example.com.

You use it to build links to your own pages in themes and plugins. Do not type the domain by hand. If you ever move the site, home_url() keeps your links correct. It is the short form of get_home_url().

Syntax

Return the URL and print it with esc_url().

WordPress
<?php echo esc_url( home_url( '/' ) ); ?>
CallWhat it does
home_url()The home URL, without a trailing slash.
home_url( '/' )The home URL with a slash. Good for the logo link.
home_url( '/contact/' )The URL of the contact page.

It returns the URL. Use esc_url() when you print it.

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

Parameters

ParameterDescription
$pathstring. A path to add after the home URL, such as /contact/. Default is empty.
$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.

WordPress Examples

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

Example 2 — Build a link to another page

Add the path of the page as the first argument.

WordPress
<?php
echo esc_url( home_url( '/contact/' ) );

How It Works

  1. /contact/ is added after the home URL.
  2. You get the full URL back.
  3. Prefer get_permalink() if you know the page ID.

Example 3 — Set a search form action

The search form should send visitors to the front of the site.

WordPress
<?php
echo '<form role="search" method="get" action="' . esc_url( home_url( '/' ) ) . '">';

How It Works

  1. A search form sends the word to the home URL.
  2. WordPress then shows the search results page.
  3. Using home_url() avoids a hard-coded domain.

Frequently Asked Questions

It returns the home URL of your site, which is the address of the front page.
home_url() is the front of your site. site_url() is where WordPress is installed. They can be different if WordPress is in a subfolder.
No. Use home_url() so your links keep working if the domain changes.
No. It returns a string. Use echo with esc_url().
Use get_home_url() with the site ID.

Next: permalink_anchor()

Print an empty anchor tag with an ID for the current post, so you can jump to it.

permalink_anchor() 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.

11 people found this page helpful