How to Get Home URL in WordPress [Example]

2.2727272727273 from 5
from 11 user
(Rate this post)
How to Get Home URL in WordPress [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.

WordPress can be installed on any sub-directory in your website host.

WordPress is not always installed on the root folder, so it becomes important to have a function returning the website’s home URL.

When 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, 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: Reterives Home URL in WordPress

get_home_url function has a simple syntax in 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 The Home URL in WP with the get_home_url Function

get_home_url function will return the home page URL; you must print it as HTML.

Example of using the get_home_url function in an HTML link:

<a href="<?php echo get_home_url(); ?>">Home Page</a>

Note: Do NOT confuse the WordPress home url with the WordPress root path.

What do you think about "How to Get Home URL in WordPress [Example]"?

Your rating submit was successfull.

Your rating submit was not successfull.

Menu