Go to main content

Site url



<txp:site_url />

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).

For more general purpose access to URLs and their components, please see the page_url tag, which includes admin (back-end) site links for both regular and multi-site installations, theme links and paths, and URL parameters.


Tag will accept the following attributes (case-sensitive) as well as the global attributes :

type="admin" v4.7.0+
Specify this if you wish to return the URL to the administration-side instead of the public site.
Default: unset.


Example 1: Maintain accurate domain paths

            <a href="<txp:site_url />articles">Articles</a>
            <a href="<txp:site_url />photos">Photographs</a>

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">

In the <head> section of your HTML pages you might have a variety of links to locations relative to the local server, such as CSS files, JavaScript files and so forth. The relevance is similar to example 1 - you want to ensure the paths are accurate relative to the server if a database has been imported from another location.

<a href="<txp:site_url />download.zip">Download</a>
<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>


Version 4.7.0

type attribute added.

If you notice any kind of problem with this page's construction or content (outdated information, typos, broken links, or whatever), open an issue to have it sorted. Or have a go at it yourself. :)