In order to speed up themes and plugins WordPress ships with lot more valuable and stronger functions like home_url() and site_url(). However, it often gets confusing terms to WP users to distinguish between these two.
Both of these term itself seems similar that is the reason most of the people just avoid knowing what basically they are than practice WP. If the WordPress is given its own directory then these two functions home-url() and site_url() return the same value.
We have been asked this question on many occasions by our readers and visitors. Here we are going to have a detailed explanation and welcome more such questionnaire from you.
When it is called site address, people often refers to the site_url() but in this case it is wrong. Let’s understand it more precisely. Consider a self-test to figure this out.
When we have a general setting, it is supposed to be WordPress Address when it refers to site_url(). If we need to dictate a physical storage path, let’s say, a correct path to locate a theme folder on the url to get it loaded header image for the website, we need other functions theme_directory_url().
Hence, site_url() is just can be located by entering into WordPress admin area or so-called dashboard by using “/wp-admin” at the end. On the other hand, home_url cannot be reliably to this location and in fact has nothing to do with that.
Here comes the two basic settings one is home_url() and the other is site_url() and the “get” the basic function they use.
Site address = home_url() = http://www.gogetspace.com/
WordPress address= site_url()=http://www.gogetspace.com/blog/ (blog has WordPress installed)
So, what we saw in above example makes it less confusing to understand between home_url() and site_url(). This happens all because of the terminology used by the WordPress itself. It has no matching association with the control and corresponds quite dissimilarly.
i.e. site_url() corresponds WordPress address whereas home_url() corresponds site address.
We already have understood that home_url() corresponds to the “Site Address”. And this is basically the general setting of a WordPress.
We can also figure it out by using syntax for that particular url.
<?php home_url($path, $scheme); ?>
e.g. home_url() = http://www.gogetspace.com/
Likewise, we have understood that site_url() will always return the “WordPress address” and that is basically the general setting of the WordPress. We can understand this by using syntax for that particular url.
<?php site_url($path, $scheme); ?>
e.g. site_url() = http://www.gogetspace.com/blog/ (blog has WordPress installed)
Now, this is the time to go deeper and understand the home_url() and site_url() by using the WordPress “Get” function. This is one of the stronger functions of WordPress and we will evaluate it to have a clear understanding.
By using Get function (home_url)
Likewise, this function returns “Site Address” as it is clearly defined in the general setting of the WordPress.
Now, when we are using the “Get” function, we need to know that this function only accepts $blog_id parameter to identify it. It is one of the stronger functions because it holds the right installation when there are multisite setups has been found.
We can use the syntax to understand it.
<?php get_home_url($blog_id, $path, $scheme); ?>
e.g. get_home_url() = http://www.gogetspace.com/
By using Get function (site_url)
When we use get function it always returns the “WordPress address” that is, however, the general setting of the WordPress.
Now, this is the time to understand that Get function accepts $blog_id parameter that makes it suitable for multiple installation. We can use the syntax from get function for better understanding.
<?php get_site_url($blog_id, $path, $scheme); ?>
In a nutshell, using the /wp-admin/ function will always provide the location of the WP Admin area (dashboard). This might differ in case of home_url() that slightly frequent in response to the site’s root directory.