Multisite get_home_url(); - Getting URL for current site

What would be the replacement for get_home_url() when using a multisite? For example, if I have one theme installed across several sites, and within the theme there are links that need to be specific to the current site.

On my single install, using get_home_url(); would give me http://domain.com/, which was great, and if I moved the theme to a different domain, nothing would be affected. But when I'm using the same theme on a multisite, get_home_url(); gives me http://domain.com/ no matter which site I am currently on. What I would need for each one is domain.com/sitename/. Is there a different tag to use in this case?

Thanks!

EDIT

Can't answer my own question yet, but ?php echo get_bloginfo( 'url' )? was exactly was I was looking for.

Topic template-tags php multisite Wordpress

Category Web


I have a not "so better", but a solution.

I've tried with your method with the following setup:

  • Localhost,
  • Using ISS
  • Wordpress version 4.1

and to get the right url I changed the wp-config.php and added this line:

define('WP_DEBUG', false);
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'localhost');
define('PATH_CURRENT_SITE', '/wordpress/');*

define('URL_SITE', 'http://'.DOMAIN_CURRENT_SITE.PATH_CURRENT_SITE );

define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

I hope that can help someone with this.


<?php echo get_bloginfo( 'url' )?> was exactly was I was looking for.


I would recommend you use home_url() to get the URL to the front page of the currently viewed site.

If you want to get the main site URL (the network home), use network_home_url().


You can use get_site_url() in combination with get_current_blog_id().

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.