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 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
Check if any column has NULL values in PostgresPostgresIs monitoring an employee’s work on a computer a desirable or undesirable activity?MiscellaneousHow to link/add CSS file to HTML Document?CSSaddcslashes() and addslashes() String Functions in PHPPHPRevisiting variable scope in JavaScriptJavaScriptCan We Use For Loop to Loop Through Associative Arrays in PHP?PHPThe SQL UNION OperatorSQL/MySQLJavaScript Data Types and Data Structures Things to RememberJavaScriptinclude, include_once, require, require_once in PHPPHPOrder By and Group By in PostgresPostgresHow to load a module with configuration in SCSS?SCSSHow to set opacity or transparency using CSS?CSS