home_url() (get the homepage link) The
ome_url() function is used to get the WordPress homepage link.
Usage
home_url( $path, $scheme );
Parameters
$path
(string) (optional) The content appended after the homepage link is a relative link.
Default value: None
$scheme
(String) (optional) Link protocol, only supports "http", "https" and "relative".
Default value: null
Return value
(String) Returns the home page URL plus the $path parameter.
Example
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
Others
This function is located at: wp-includes/link-template.php
site_url() (get site link)
site_url() function is used to get the WordPress site link.
Usage
site_url( $path, $scheme );
Parameters
$path
(String) (optional) Content appended after the link.
Default: None
$scheme
(String) (optional) Link protocol, only "http", "https", "login", "admin" and "relative" are allowed.
Default value: null
Return value
(String) Returns the site link plus the $path parameter.
Example
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/
Others
This function is located at: wp-includes/link-template.php
The above is an introduction to the PHP functions used to obtain homepage and site links in WordPress, including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.