函数文档

_config_wp_siteurl()

💡 云策文档标注

概述

_config_wp_siteurl() 函数用于检索 WordPress 站点 URL,优先返回 WP_SITEURL 常量定义的值,适用于本地调试场景。

关键要点

  • 如果定义了 WP_SITEURL 常量,函数始终返回该常量值,并自动移除尾部斜杠。
  • 参数 $url 为可选字符串,当 WP_SITEURL 未定义时,函数返回传入的 $url 值。
  • 函数返回类型为字符串,表示 WordPress 站点 URL。
  • 相关函数 untrailingslashit() 用于移除尾部斜杠,确保 URL 格式规范。
  • 自 WordPress 2.2.0 版本引入此函数。

代码示例

function _config_wp_siteurl( $url = '' ) {
	if ( defined( 'WP_SITEURL' ) ) {
		return untrailingslashit( WP_SITEURL );
	}
	return $url;
}

📄 原文内容

Retrieves the WordPress site URL.

Description

If the constant named ‘WP_SITEURL’ is defined, then the value in that constant will always be returned. This can be used for debugging a site on your localhost while not having to change the database to your URL.

See also

Parameters

$urlstringrequired
URL to set the WordPress site location.

Return

string The WordPress site URL.

Source

function _config_wp_siteurl( $url = '' ) {
	if ( defined( 'WP_SITEURL' ) ) {
		return untrailingslashit( WP_SITEURL );
	}
	return $url;
}

Changelog

Version Description
2.2.0 Introduced.