How to get Home URL in WordPress? (Usage Example)

get_home_url retrieves the Home Page URL of a WordPress website. get_home_url is one of the most used WordPress functions by developers when they want to use links in the development process. Let's have a better look at this function with an example.

5 from 5
from 1 user
(Rate this post)

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>

What do you think about "How to get Home URL in WordPress? (Usage Example)"?

Your rating submit was successfull.

Your rating submit was not successfull.

Menu