WordPress has 2 inbuilt functionalities to get the site url:
site_url();
The site_url()
will always be the location where you can reach the site by tacking on /wp-admin
on the end, while home_url()
would not reliably be this location. You can also get this same field by using get_bloginfo( 'wpurl' )
.
home_url();
The home_url()
would be where you have set your homepage by setting General > Settings “Site Address (URL)” field. You can get this same field by using get_bloginfo( 'url' )
as well.