Using Textpattern CMS `site_name`, `site_slogan` and `site_url` tags


Textpattern CMS-powered websites can make use of an extensive array of tags, which translate into markup on the rendered page. Many of the tags can be used to extract information from individual content items, be it an article, image, file or comment. Some tags, however, operate at a much more broad level outside of any content items, and these three will extract information about the website:

  • site_name
  • site_slogan
  • site_url

All three are single tags. None of them have attributes. They are, bluntly, intended to one thing: extract the site name, the site slogan and site URL. The information they extract is plain text, which lends itself to formatting (extensive or not) outside the tag in order to pep-up the result.

I’ll use a fictitious site for the following example code. It’s running Textpattern and the administration preferences are set as follows:

  • the site name is: `The Wonderful World of Smoked Cheeses`
  • the site slogan is: `[or: how I learned to stop worrying and love Austria]`
  • the site address is: ``

I say it’s fictitious, I’m writing this on a Sunday afternoon and plucking that site name from the top of my head has given me all kinds of ideas to start a site about smoked cheeses, so it might not be fictitious for long. The reason you’ll see `` mentioned in technical documentation frequently is because it’s one of a bunch of RFC-approved websites that can be used for this sort of thing. More info at RFC2606 if you’re interested in that kind of thing.

Enough of the RFC talk, let’s get back to cheese.

In their simplest incarnations, the three tags tally up with the corresponding settings in the administration preferences listed above.

Typically, the settings for the website name, slogan and URL won’t change often, if at all. With that, there’s a school of thought that says it’s perhaps worth hard-coding these values into the site page templates and articles. As sites grow in size and complexity, it becomes more time-consuming to search and replace instances of hard-coded information, even with a MySQL query.

If a site is set to move domains, or switch to a subdomain, or change name, there’s already a big chunk of stuff to do in order for that to happen. Understanding how these three (admittedly quite mundane) tags work and integrating them into your site in your role as an administrator or author will save a whole lot of work. The crucial thing to bear in mind is that if one or more of the name, slogan or URL change then the tags will keep up – they will extract and output the current value for each and that will end up in your site and feeds. If you’re involved with developing Textpattern sites, you may use a development domain or staging area; changing the site URL and using the `site_url` tag will keep things in order. When you move from development/staging to production, simply update the URL and all references to `site_url` will keep up.

I’ll build an example so you can understand better how these three tags can be rolled out. Ultimately I want to have a clickable text anchor title across all my pages so my visitors can visit the homepage of my cheesy website. I’ll start by having the site name as an `h1` header:

<h1><txp:site_name /></h1>

Next, I want to add the slogan as an `h2` underneath:

<h1><txp:site_name /></h1>
<h2><txp:site_slogan /></h2>

As it stands, this will simply extract the name and slogan and wrap them in the `h1` or `h2` accordingly. I want to hyperlink the name to the homepage, and have the slogan link through to an about page. The first part is easy enough:

<h1><a href="<txp:site_url />"><txp:site_name /></a></h1>
<h2><txp:site_slogan /></h2>

The second part, hyperlinking the slogan, has one gotcha to be aware of: the site URL includes a trailing slash. This is the preferred way to do it:

<h1><a href="<txp:site_url />"><txp:site_name /></a></h1>
<h2><a href="<txp:site_url />about"><txp:site_slogan /></a></h2>

Note there is no ‘forward slash about’ in the `h2` block hyperlink; the link will still go to ``.

Next time: `page_title` and `page_url`. And absolutely no mention of smoked cheeses. Probably.

Looking for quality Textpattern Hosting? Look no further than Arvixe Web Hosting and use coupon TEXTPATTERN for 20% off your first invoice!

Tags: , , , , , , , , , , , , | Posted under Textpattern | RSS 2.0

Author Spotlight

Pete Cooper

Pete Cooper has been using Textpattern since 2005. Textpattern is his preferred CMS weapon of choice. Its logical and flexible approach to content management makes Pete happy, as does its lightweight core and helpful user community. Pete's website - - runs on top of Textpattern and chronicles his day-to-day experiences from his home near the Atlantic in north Cornwall, United Kingdom.

Leave a Reply

Your email address will not be published. Required fields are marked *