WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/home url

Contents

Description

The home_url template tag retrieves the home URL for the current site, optionally with the $path argument appended. The function determines the appropriate protocol, "https" if is_ssl() and "http" otherwise. If the $scheme argument is "http" or "https" the is_ssl() check is overridden.

In case of WordPress Network Setup, use network_home_url() instead.

Usage

<?php home_url$path$scheme ); ?>

Default Usage

<?php echo esc_urlhome_url'/' ) ); ?>

Parameters

$path
(string) (optional) Path relative to the home URL.
Default: None
$scheme
(string) (optional) Scheme to use for the home URL. Currently, only "http", "https" and "relative" are supported.
Default: null

Return

(string) 
Home URL with the optional $path argument appended.

Example

$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

Notes

Changelog

Source Code

home_url() is located in wp-includes/link-template.php.

Related

WordPress Directories:
home_url() Home URL http://www.example.com
site_url() Site directory URL http://www.example.com or http://www.example.com/wordpress
admin_url() Admin directory URL http://www.example.com/wp-admin
includes_url() Includes directory URL http://www.example.com/wp-includes
content_url() Content directory URL http://www.example.com/wp-content
plugins_url() Plugins directory URL http://www.example.com/wp-content/plugins
theme_url() Themes directory URL (#18302) http://www.example.com/wp-content/themes
wp_upload_dir() Upload directory URL (returns an array) http://www.example.com/wp-content/uploads
See also index of Function Reference and index of Template Tags.