Yogesh Chauhan's Blog

How to retrieve homepage URL in WordPress?

in WordPress on October 16, 2020

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

Credit: developer.wordpress.org


Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
Array destructuring and Object destructuring in JavaScriptJavaScriptHow to convert datetime to date format in JavaScript?JavaScriptSequence generator (range) using JavaScript Array.from()JavaScriptNumber Properties in JavaScriptJavaScriptWhat are components in Angular?AngularPHP __construct() functionPHPHow to create ‘share on LinkedIn’ link using just HTML?HTMLfor @each loop in SCSSSCSSHow to catch .keypress() on body using jQuery?jQueryFile System Integrity: How to Keep an Eye on Your Files and Folder Change?Miscellaneous10 Usability Blunders to AvoidUI/UXperspective property in CSSCSS