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

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
LIMIT and OFFSET in PostgresPostgresHow to install Gulp with WordPress?WordPressKilling A Project Part 2: Who should make the decision to kill a project?MiscellaneousHow to create a flip pricing table using CSS and JavaScript?CSSComponents and Props in ReactReactIntroduction to Angular modules Part 1: NgModule metadataAngularWhat is an API?MiscellaneousIntroduction to components and templates Part 1: Component MetadataAngularHow to add AppRoutingModule in Angular application using command line?AngularOverview of Drupal and how it worksDrupalHow to float an image around texts?CSSHow to disable the Recovery Mode in WordPress?WordPress