get_site_url()
is a WordPress function used to retrieve the URL of the current site. Here’s how to use it:
- Retrieve the site URL:
scss
$site_url = get_site_url();
This code retrieves the URL of the current site.
- Display the site URL:
bash
echo $site_url;
This code displays the URL of the current site retrieved in step 1.
You can also use get_site_url()
to retrieve the URL of a specific site within a multisite network:
bash
$site_url = get_site_url( $blog_id );
Replace $blog_id
with the ID of the site you want to retrieve the URL for. If you don’t specify a blog ID, the function will use the current site.
Note that get_site_url()
should not be confused with get_home_url()
, which retrieves the URL of the site’s homepage.