Example 1 — Print the site URL
Imagine WordPress lives in a /wp folder.
<?php
echo esc_url( site_url() ); How It Works
site_url()returns where WordPress is installed.- Here it is the
/wpfolder. - On a normal site you would see only the domain.

In WordPress, site_url() returns the site URL of the current site. This is the address where the WordPress core files live, such as wp-login.php and wp-admin.
On most sites it is the same as home_url(). They differ when WordPress is installed in a subfolder, for example /wp, while the front page uses the main domain.
Return the URL and print it with esc_url().
<?php echo esc_url( site_url() ); ?> | Call | What it does |
|---|---|
site_url() | The site URL. |
site_url( 'wp-login.php' ) | The login page URL. |
site_url( '/wp-admin/', 'relative' ) | A relative path to the admin. |
It returns a string. For links to the front of your site, use home_url().
site_url( string $path = '', string|null $scheme = null ): string | Parameter | Description |
|---|---|
$path | string. A path to add after the site URL, such as wp-login.php. |
$scheme | string|null. http, https, login, login_post, admin, or relative. Default is null. |
| Return Value | Description |
|---|---|
| string | The site URL, with the path added when you pass one. |
Three short examples. Each one shows the code and what it prints or does.
Imagine WordPress lives in a /wp folder.
<?php
echo esc_url( site_url() ); site_url() returns where WordPress is installed./wp folder.Add a path to reach a WordPress file.
<?php
echo '<a href="' . esc_url( site_url( 'wp-login.php' ) ) . '">Log in</a>'; wp-login.php is added to the site URL.home_url().The relative scheme removes the domain.
<?php
echo esc_url( site_url( 'wp-login.php', 'relative' ) ); relative returns only the path.https to force a secure URL instead.Print a link to a site feed (RSS or Atom) with the text you choose.
17 people found this page helpful