📜  siteurl - PHP (1)

📅  最后修改于: 2023-12-03 15:20:09.052000             🧑  作者: Mango

siteurl - PHP

The siteurl function is a built-in WordPress function that retrieves the site's url as set in the database. This function is useful for plugin and theme developers who need to dynamically generate links to different pages or assets on the site.

Syntax
<?php site_url( $path = '', $scheme = null ); ?>
Parameters
  • $path (optional): string The path to append to the url. Defaults to empty string.
  • $scheme (optional): string The scheme to use for the url. Defaults to null which means the scheme will be determined dynamically.
Return Value

The siteurl function returns the full site url including the scheme and domain name.

Examples
<?php 
$login_url = site_url('/wp-login.php');
echo "<a href='$login_url'>Login</a>";
?>

This code will output a link to the WordPress login page. If WordPress is installed on localhost and the current page is http://localhost/page, then the link generated will be http://localhost/wp-login.php.

<?php 
$image_url = site_url('/wp-content/uploads/2021/07/image.jpg', 'https');
echo "<img src='$image_url'>";
?>

This code will output an image tag that displays an image located in the wp-content/uploads/2021/07 directory of the site. The https scheme is used for the url.

The Markdown code for the same:
# siteurl - PHP

The `siteurl` function is a built-in WordPress function that retrieves the site's url as set in the database. This function is useful for plugin and theme developers who need to dynamically generate links to different pages or assets on the site.

## Syntax


## Parameters

 - `$path` (optional): string The path to append to the url. Defaults to empty string.
 - `$scheme` (optional): string The scheme to use for the url. Defaults to null which means the scheme will be determined dynamically.

## Return Value

The `siteurl` function returns the full site url including the scheme and domain name.

## Examples

Login"; ?>

This code will output a link to the WordPress login page. If WordPress is installed on `localhost` and the current page is `http://localhost/page`, then the link generated will be `http://localhost/wp-login.php`.

"; ?>

This code will output an image tag that displays an image located in the `wp-content/uploads/2021/07` directory of the site. The `https` scheme is used for the url.