目录
描述
site_url() 方法可以获取博客的网址并显示,返回的是数据库中wp_options 表 siteurl 字段的值,指向wordpress核心文件URL,也就是安装路径。如果是要显示站点首页的网址,可以通过 home_url() 方法进行获取。
如果是需要调用SSL协议的网址,请使用 network_site_url() 方法进行替代。
SITE_URL() 描述
用法
参数
$path
(string) (可选) Path to be appended to the site url.
默认值: None
$scheme
(string) (可选) Context for the protocol for the url returned. Setting $scheme will override the default context. Allowed values are 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
默认值: null
SITE_URL() 参数
示例
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ $url = site_url(); echo $url;
Output: http://www.example.com or http://www.example.com/wordpress
(Note the lack of a trailing slash)
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ $url = site_url( '/secrets/', 'https' ); echo $url;
Output: https://www.example.com/secrets/ or https://www.example.com/wordpress/secrets/
SITE_URL() 示例
注意
- 使用到 get_site_url()
- 使用到 the 'siteurl' option
SITE_URL() 注意
- 原文:http://codex.wordpress.org/Function_Reference/site_url
- 翻译:黄聪@WordPress之魂