YogeshChauhan.com
How to retrieve homepage URL in WordPress?
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

https://www.yogeshchauhan.com

$url = home_url( '/' );
echo $url;

// Output

https://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

dreamhost

Leave a Reply

Most Read

#1 How to set opacity or transparency using CSS? #2 Pagination in CSS with multiple examples #3 How to check if radio button is checked or not using JavaScript? #4 How to make HTML form interactive and using CSS? #5 How to uninstall Cocoapods from the Mac OS? #6 How to add Read More Read Less Button using JavaScript?



Recently Posted

Feb 24 How to modify the latest post array using get_posts() in WordPress? Feb 22 WordPress: How to get ACF field values from another post? Feb 22 WordPress: How to print ACF repeater field values? Feb 22 WordPress: How to print ACF array field values? Feb 21 WordPress: How to get field values in Advanced Custom Fields? Feb 21 WordPress: How to add a Search Icon in Menus with toggle effect using jQuery?



You might also like these

How to create a simple tab interaction using CSS?CSSHow to change CSS with JavaScript?CSSHow to create a link tag button using CSS?CSSHow to Validate User Name, Email Address and URL in PHP?PHPHow to find the HCF or GCD and LCM of two given numbers using Swift?SwiftWhat are components in Angular?AngularLearn to Make a Simple Contact Us Form using PHP and PDO-MySQLPHPbin2hex() and chr() String Functions in PHPPHPSolution for Xcode 11 Command PhaseScriptExecution failed with a nonzero exit code errorMiscKilling A Project Part 2: Who should make the decision to kill a project?MiscThe Lending Club Analysis using Logistic Regression and Random Forest in RStudioMiscThe order Property in Flex Items in CSSCSS