Home WordPress Links Functions get_site_url() WordPress get_site_url() Function Definition In WordPress, get_site_url() returns the site URL . This is the address where the WordPress core files live, the place that holds wp-admin and wp-login.php.
Most sites use the same address for the front page and for WordPress. If you install WordPress in a subfolder, such as /wp, they can differ. The first argument lets you pick a site on a multisite network.
Syntax Return the URL and print it with esc_url().
<?php echo esc_url( get_site_url() ); ?> Call What it does get_site_url()The site URL of the current site. get_site_url( null, 'wp-login.php' )The login page URL. get_site_url( 2 )The site URL of site 2 on a multisite.
It returns a string. For the address of the front page, use get_home_url().
Full declaration get_site_url( int|null $blog_id = null, string $path = '', string|null $scheme = null ): string Parameters Parameter Description $blog_idint|null. Site ID on a multisite. Default is null, the current site. $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 Value Description string The 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.
1. Print the site URL 2. Link to the login page 3. Compare site URL and home URL Example 1 — Print the site URL The simplest call. Imagine WordPress is installed in a /wp folder.
<?php
echo esc_url( get_site_url() ); How It Works get_site_url() returns where WordPress is installed.In this example the install folder is /wp. On a normal site you would see https://example.com. Example 2 — Link to the login page Add a path to point to a WordPress file.
<?php
echo esc_url( get_site_url( null, 'wp-login.php' ) ); https://example.com/wp/wp-login.php How It Works null means the current site.wp-login.php is added to the site URL.This is the real login page, even in a subfolder. Example 3 — Compare site URL and home URL See the difference side by side.
<?php
echo 'Home: ' . esc_url( get_home_url() ) . "\n";
echo 'Site: ' . esc_url( get_site_url() ); Home: https://example.com
Site: https://example.com/wp How It Works get_home_url() is the address visitors use.get_site_url() is where WordPress is installed.They match on most sites, but they do not have to. Frequently Asked Questions What does get_site_url() do? It returns the address where WordPress is installed. That is the base for wp-admin and wp-login.php.
What is the difference between site URL and home URL? Home URL is the address of your front page. Site URL is where WordPress files live. They are the same on most sites.
What is the difference between get_site_url() and site_url()? site_url() is the short version for the current site. get_site_url() lets you choose a site on multisite.
Does it print the URL? No. It returns it. Use echo with esc_url().
Where do I change the site URL? In Settings, then General, under WordPress Address (URL).
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
5 people found this page helpful
Helpful Share Copy link Suggestion