Home  >  Article  >  Backend Development  >  简介WordPress中用于获取首页和站点链接的PHP函数_php技巧

简介WordPress中用于获取首页和站点链接的PHP函数_php技巧

WBOY
WBOYOriginal
2016-05-16 20:02:431048browse

home_url()(获取首页链接)
ome_url() 函数用来获取 WordPress 的首页链接。

用法

home_url( $path, $scheme );

参数

$path

(字符串)(可选)在首页链接后边追加的内容,是相对链接。

默认值:None

$scheme

(字符串)(可选)链接协议,只支持 “http”,“https” 和 “relative”。

默认值:null

返回值

(字符串)返回首页 URL 加上 $path 参数。

例子

echo home_url();//输出:http://www.example.com
echo home_url( '/' );//输出:http://www.example.com/
echo home_url( '/', 'https' );//输出:https://www.example.com/
echo home_url( 'example', 'relative' );//输出:/example

其它
此函数位于:wp-includes/link-template.php


site_url()(获取站点链接)
site_url() 函数用来获取 WordPress 的站点链接。

用法

site_url( $path, $scheme );

参数

$path

(字符串)(可选)在链接后追加的内容。

默认值:None

$scheme

(字符串)(可选)链接协议,只允许 “http”、“https”、“login”、“admin” 和 “relative”。

默认值:null

返回值

(字符串)返回站点链接加上 $path 参数。

例子

echo site_url();//输出:http://www.example.com 或者 http://www.example.com/wordpress
echo site_url( '/secrets/', 'https' );//输出:https://www.example.com/secrets/ 或者 https://www.example.com/wordpress/secrets/

其它

此函数位于:wp-includes/link-template.php


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn