We can use home_url() function from WordPress to get the homepage URL, considering the front end is accessible.
Syntax
home_url( $path = ' ', $scheme )
where $path can be string and $scheme can be null or string
Note: Path is the relative path to the home URL.
$scheme accepts 'http', 'https', 'relative', 'rest', or null and the default value is null.
Examples
$url = home_url();
echo $url;
//Output
http://www.yogeshchauhan.com
$url = home_url( '/' );
echo $url;
// Output
http://www.yogeshchauhan.com/
$url = home_url( $path = '/', $scheme = 'https' );
echo $url;
// Output
https://www.yogeshchauhan.com/
$url = home_url( $path = 'yogeshchauhan', $scheme = 'relative' );
echo $url;
// Output
/yogeshchauhan
Credit: developer.wordpress.org
examples functions home_url url