WordPress can be installed on any sub-directory in your website host.
Not all of the time WordPress is installed on the root folder, so it becomes important to have a function returning the current website’s URL.
When you are developing WordPress themes or plugins, Using relative addresses for file reference or link building is NOT a great idea.
You should never use fixed URLs also!
The reason is clear, addresses may change due to differences in WordPress installation, selected options, and etc.
A good practice for making a linked reference to a website is using the
get_home_url function in PHP.
get_home_url Function Syntax
This function has a simple syntax in the WordPress:
get_home_url($blogId = null, $path = '', $scheme = null)
If you are using WordPress for a single website, pass a null value for
$blogId (default is null also).
$path is the relative path from the home URL.
$scheme can be one of these values: ‘http’, ‘https’, ‘relative’, ‘rest’, or null.
get_home_url Function Usage
This function will return the home page URL and you need to print it as HTML if you want.
Example of using get_home_url function in a HTML link:
<a href="<?php echo get_home_url(); ?>">Home Page</a>