_config_wp_home()
云策文档标注
概述
_config_wp_home() 函数用于获取 WordPress 首页 URL,优先返回 WP_HOME 常量定义的值,适用于本地开发环境重定向处理。
关键要点
- 函数检查 WP_HOME 常量是否存在,若存在则返回其值(使用 untrailingslashit() 去除尾部斜杠)
- 如果 WP_HOME 未定义,则返回传入的 $url 参数
- 函数自 WordPress 2.2.0 版本引入,相关函数包括 untrailingslashit()
代码示例
function _config_wp_home( $url = '' ) {
if ( defined( 'WP_HOME' ) ) {
return untrailingslashit( WP_HOME );
}
return $url;
}
原文内容
Retrieves the WordPress home page URL.
Description
If the constant named ‘WP_HOME’ exists, then it will be used and returned by the function. This can be used to counter the redirection on your local development environment.
See also
Parameters
$urlstringrequired-
URL for the home location.
Source
function _config_wp_home( $url = '' ) {
if ( defined( 'WP_HOME' ) ) {
return untrailingslashit( WP_HOME );
}
return $url;
}
Changelog
| Version | Description |
|---|---|
| 2.2.0 | Introduced. |