最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme development - get main URL from subdirectory with php

programmeradmin4浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

site_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.

发布评论

评论列表(0)

  1. 暂无评论