Get the installation URL of WordPress

In some cases, it can be very helpful to use the WordPress installation URL for a PHP validation procedure. The following example shows how easily you can get the installation URL of WordPress by using a small PHP function.

How do I get the correct URL of the WordPress installation?

The following PHP function is helping us to figure out the installation URL WordPress. This wrapper function uses the WordPress own function get_site_url(); to do this:

The benefit of this function is that it will output the current and correct installation URL even if WordPress is running on multisite instances.

It should also be noted that we use get_site_url(); to get the currently used installation path. For example, if WordPress is installed in a subdirectory. In this case, our function would then output “” instead of just the main domain. This is important in special cases, if several WordPress installations using the same domain name.

A common mistake is to use the WordPress get_home_url(); function instead, to get the web url of our WordPress installation. Because this function always outputs only the domain name. Even if the active installation is installed in a subdirectory.