函数文档

wxr_site_url()

💡 云策文档标注

概述

wxr_site_url() 函数用于返回站点的 URL,根据是否为多站点环境选择不同的内部函数来获取 URL。

关键要点

  • 函数返回站点 URL 的字符串。
  • 在多站点环境下,使用 network_home_url() 返回网络主页 URL。
  • 在单站点环境下,使用 get_bloginfo_rss('url') 返回站点 URL。
  • 函数自 WordPress 2.5.0 版本引入。

代码示例

function wxr_site_url() {
    if ( is_multisite() ) {
        // Multisite: the base URL.
        return network_home_url();
    } else {
        // WordPress (single site): the site URL.
        return get_bloginfo_rss( 'url' );
    }
}

注意事项

  • 函数内部依赖于 is_multisite() 来判断环境,确保正确使用相关函数。
  • 主要用于 WXR 导出功能,如 export_wp() 函数中调用。

📄 原文内容

Returns the URL of the site.

Return

string Site URL.

Source

function wxr_site_url() {
	if ( is_multisite() ) {
		// Multisite: the base URL.
		return network_home_url();
	} else {
		// WordPress (single site): the site URL.
		return get_bloginfo_rss( 'url' );
	}
}

Changelog

Version Description
2.5.0 Introduced.