Get WordPress home url or front page url

In WordPress Home URL or site URL is mainly used to make a redirect to the home page by clicking on the logo or a special link on any position of the body or it is also used to link some static component. Now start WordPress get home URL

The basic way

The basic code to get home URL is home_url()
Example:

<?php echo home_url(); ?>

or the home URL can be fetched by the code get_bloginfo(‘url’)
Example:

<?php echo get_bloginfo('url'); ?>

Print s slash (/) on the last of Home Url

the code is used to print a slash (/) is home_url( '/' )
Example:

<?php echo esc_url( home_url( '/' ) ); ?>

Redirect to https

To redirect https if it is not defined in base URL then have to pass another parameter ‘https’ on the code home URL
Example:

<?php
$url = home_url( '/', 'https' );
echo esc_url( $url );
?>

I hope the post WordPress get home URL helped you, please provide your comment to make the site better and more useful.

Thanks for Reading

Share The Post On -