Textpattern tips, tutorials and code snippets

Nice custom page titles for Textpattern sites

It’s no secret that SuperawesømeTextpattern. We love working with the CMS, especially because of the special way templating is implemented that’s super–easy for a designer to understand.

One thing that’s kind of difficult to achieve, is the complete customization of the page titles. For some reason, I like a site to be completely customized, and I am really happy Textpattern offers this level of fine–grained control over content.

Customized Page Titles in Textpattern

I usually have a couple of rules when it comes to page titles:

  • I want a special title on the home page,
  • I want a special title on the section lander,
  • I want a special title on the category lander within a section (for articles that are within categories, and sections),
  • I want a special title on the individual article page.

In order to achieve this, use this Textpattern template code:

<title>

  <txp:hide>check to see if we're on the home page</txp:hide>

  <txp:if_section name="">

    <txp:hide>we are, display the site's name and slogan</txp:hide>

    <txp:site_name /> — <txp:site_slogan />

  <txp:else />

    <txp:hide>we're not on the home page, check to see if we're in an article listing</txp:hide>

    <txp:if_article_list>

      <txp:hide>check to see if we are in a category listing</txp:hide>

      <txp:if_category>

        <txp:hide>we're in a category listing, display the category and section titles</txp:hide>

        <txp:category title="1" /> — <txp:section title="1" />

        <txp:else />

        <txp:hide>we're in a regular section listing, display section title</txp:hide>

        <txp:section title="1" />

      </txp:if_category>

    </txp:if_article_list>

    <txp:hide>check to see if we're on an individual article page</txp:hide>

    <txp:if_individual_article>

      <txp:hide>we are on an individual article page</txp:hide>

      <txp:title />

      <txp:hide>check to see if the article is in a category</txp:hide>

      <txp:if_article_category>

        <txp:hide>it is, display category2 title (for you this may be category1)</txp:hide>

        — <txp:category2 title="1" />

      </txp:if_article_category>

      <txp:hide>display article's section title</txp:hide>

      — <txp:section title="1" />

    </txp:if_individual_article>

    <txp:hide>always display the site's name</txp:hide>

    | <txp:site_name />

  </txp:if_section>

</title>

See the GitHub gist or the blog post for more!

3 Comments Comment feed

Hi Dragan,

I’m looking to use custom fields to create a page title so that an SEO team can specify the exact wording that they want within the <title> of each page and section. This does not always correspond directly to the article title or the section.

I am struggling to get TXP to recognize custom fields in the heading section.

Do you have any tips or ideas that you could share?

  • Mave
  • 19 May 2012

Liam, there’s a good article on managing titles here. It worked like a charm for me.

Here is another method of managing SEO titles in Textpattern without plugins.

Add a comment

Use Textile help to style your comments