How to get link to homepage

echo esc_url( home_url( "https://wordpress.stackexchange.com/" ) ); this best practice.

get_bloginfo( $show, $filter );

It has lots of Parameters to get info so
let see the ##SHOW(Parameters):
name,description,wpurl,url,admin_email,charset,version,html_type,text_direction,language,stylesheet_url,stylesheet_directory,template_url,pingback_url,atom_url,rdf_url,rss_url,rss2_url,comments_atom_url,comments_rss2_url,siteurl,home
so if you want to use this finction you have to use like get_bloginfo(‘wpurl’); or get_bloginfo(‘url’);

These two functions home_url() and site_url() return the same value (WordPress address or URL) if WordPress hasn’t been given its own directory.Say you installed a WordPress blog in the root folder of example(dot)com but the core WordPress files was moved to a sub-directory named wp-core.The function home_url() will return example(dot)com and site_url() will return example(dot)com/wp-core.

A few notes:

  1. home_url() will only return the mapped domain on or after the init has fired. Calling it before then will return the wordpress.com domain.
  2. If you accidentally use site_url() in your templates, theme-side links will still redirect correctly to the home_url() equivalent.
  3. home_url() is the preferred method, as it avoids the above redirect.

I think you are clear about this what you need to use for your work 🙂
Happy Coding 🙂
Musa