WordPress site_url() Function

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

Definition

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.

Syntax

Return the URL and print it with esc_url().

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

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

Parameters

ParameterDescription
$pathstring. A path to add after the site URL, such as wp-login.php.
$schemestring|null. http, https, login, login_post, admin, or relative. Default is null.

Return Value

Return ValueDescription
stringThe site 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 1 — Print the site URL

Imagine WordPress lives in a /wp folder.

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

How It Works

  1. site_url() returns where WordPress is installed.
  2. Here it is the /wp folder.
  3. On a normal site you would see only the domain.

Example 2 — Link to the login page

Add a path to reach a WordPress file.

WordPress
<?php
echo '<a href="' . esc_url( site_url( 'wp-login.php' ) ) . '">Log in</a>';

How It Works

  1. wp-login.php is added to the site URL.
  2. This always points to the real login file.
  3. For the front of the site you would use home_url().

Example 3 — Get a relative path

The relative scheme removes the domain.

WordPress
<?php
echo esc_url( site_url( 'wp-login.php', 'relative' ) );

How It Works

  1. relative returns only the path.
  2. That helps when the same code runs on many domains.
  3. Use https to force a secure URL instead.

Frequently Asked Questions

It returns the URL where WordPress is installed for the current site.
site_url() points to the WordPress install. home_url() points to the front page of your site. They are the same on most sites.
When you link to WordPress files, such as wp-login.php or wp-admin.
No. It returns a string. Use echo with esc_url().
Use get_site_url() and pass the site ID.

Next: the_feed_link()

Print a link to a site feed (RSS or Atom) with the text you choose.

the_feed_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.

17 people found this page helpful