I have a WordPress site that contains multiple subdirectory installations of WordPress with individual databases inside one WordPress installation, and I want to link them together in the themes. But I couldn't figure out how to dynamically get the main URL from the base WordPress directory for one of the subdirectories.
For example, I tried to use get_home_url() but it only returns instead of
This might be something basic but i couldn't find anything in my resarch that could help me out.
I have a WordPress site that contains multiple subdirectory installations of WordPress with individual databases inside one WordPress installation, and I want to link them together in the themes. But I couldn't figure out how to dynamically get the main URL from the base WordPress directory for one of the subdirectories.
For example, I tried to use get_home_url() but it only returns https://mytestsite.com/instance1 instead of https://mytestsite.com
This might be something basic but i couldn't find anything in my resarch that could help me out.
Share Improve this question asked Feb 16, 2022 at 11:08 PellePelle 152 bronze badges 1- Can you clarify if this is a WP Multi site? By the way you described it, it sounds like its multiple individual installs and not a multi site. – Bazdin Commented Feb 16, 2022 at 15:52
1 Answer
Reset to default 0site_url
gets you the current sites URL, but you can get the site URL of the root blog at /
via get_site_url
by passing its ID, which is likely to be 1
, e.g.:
$url = get_site_url( 1 );
As an aside, you may find switch_to_blog
and restore_current_blog
to be useful, just know that they're not cheap to call, and it won't load code from the other blog/site, if the other site relies on a custom plugin or filters it won't be present unless it's also present on the current site.