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 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
How to create a new HTML element programmatically using JavaScript?HTMLHow To Create a Fullscreen Background Video using CSS and JavaScript?CSSAttributes and Properties in JavaScript and HTMLHTMLThe simple difference between var, let and const in JavascriptJavaScriptWhat’s a Log File and What are Log File Monitors?MiscellaneousWordPress: How to print ACF repeater field values?WordPressHow to use GROUPING SETS to boost GROUP BY queries in Postgres?PostgresControl Scrolling with CSS Scroll SnapCSSHow to read Standard Input in Swift?SwiftHow to use Context in React?ReactSQL Inner JoinSQL/MySQLSelect statement in Postgres with examplesPostgres