Tutorial Example

Understand WordPress home_url() for Beginngers – WordPress Tutorial

WordPress home_url() can return or print wordpress site home url, in this tutorial, we will introduce how to use this function by using some simple examples.

Save site home url to variable

$url = home_url();
echo $url;

Output:

https://www.tutorialexample.com

Set home url to end with ‘/’

$url = home_url( '/' );
echo $url;

Output:

https://www.tutorialexample.com/

Set home url to start with https

$url = home_url( $path = '/', $scheme = https );
echo $url;

Output:

https://www.tutorialexample.com/

Get relative path

$url = home_url( $path = 'example', $scheme = relative );
echo $url;

Output:

/example