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

Source: https://developer.wordpress.org/reference/functions/home_url/

0 Comments

Leave a reply

Your email address will not be published. required fields are marked *