On this page:
The site_url tag is a single tag which returns the full URL of the site (as defined in the Preferences panel) as text. If you maintain local development versions of your live sites and import databases between them, then this tag is extremely valuable for ensuring your domain links are never confused (and thus broken) between the two locations (see example 1, below).
Tag will accept the following attribute (case-sensitive):
- Specify this if you wish to return the URL to the admin-side instead of the public site.
- Default: unset.
Example 1: Maintain accurate domain paths
<nav> <ul> <li> <a href="<txp:site_url />articles">Articles</a> </li> <li> <a href="<txp:site_url />photos">Photographs</a> </li> </ul> </nav>
A classic example is with navigation links - the idea is that you don’t break URL paths after importing a database from local development to live, or vice versa. By using this tag it will automatically be relative to a given site and you’ll never have to manually edit broken domain paths again.
Example 2: HTML header paths
<link rel="stylesheet" href="<txp:site_url />assets/css/main.css">
Example 3: Display a hyperlink to download a .ZIP file
<a href="<txp:site_url />download.zip">Download</a>
Example 4: Link to the admin side
<a href="<txp:site_url type="admin" />">Login to Textpattern here</a>
Example 5: Parse site URL without the trailing slash
<a href="<txp:site_url trim="/" />">Login to Textpattern here</a>
type attribute added.