Typo3: To Each Their Own - Site And Page Titles In Alternative Languages

Submitted by Hannes Schmidt on Wed, 09/08/2004 - 03:44.

Problem 1: The Site Title Is Global

Your site supports multiple languages using the "modern" single-tree aproach where one page has one or more translations in alternative languages. In Typo3 every page's title usually starts with the site title and the page title is appended to it. The page title can easily be translated by customizing the language-specific header fields. The site title, however, can only be set globally. Consider yourself lucky if your site title is universal across languages. Mine isn't. Furthermore, I like my site's title to contain main search engine keywords, i.e. the words I want my site to be found under in Google, Yahoo and so on.

Update 25.11.2004: This is not quite correct. There is the site name ($TYPO3_CONF_VARS['SYS']['sitename']) that is only used in the backend and there is the site title for the frontend. The site title can be set per template and it affects all pages below the page that has the template. Thanks to Michael Stucki for pointing this out. If you wanted to have a different title for every page, you could create an extension template for each page. In this case it would be easier to set the site title to an empty string in the root template and adjust the title in each page's header. The latter approach could also be used to set the page header in multiple languages as the page title header field is language specific. But be aware that this is not recommended if the title of all pages has a commmon beginning or ending. You would end up duplicating this prefix or postfix on every page. This violates information technology rule number 213: Duplication Is Bad. It Steals Your Time.

Problem 2: Navigation Titles Are Ignored For Alternative Languages

Normally, the page title is not only used in the title tag but also for navigation. The page title appears in menus, bread crumb trails, site-maps and so on. Sometimes it's better to use short texts for navigation and longer texts for title tags. For example, if your were selling protective gear for animals, "Hamster Gloves" would be good for navigation, but "Buy Hamster Gloves In Florida" would be good for the title tag. Keep in mind that Google and Yahoo use the title tag of your page in their search results. Also, most users decide to click on or ignore your page's listing based on its title tag. Typo3 supports this distinction by letting you specifiy a page title and a navigation title. If a page has a page title and a navigation title, the navigation title will be used for navigation (hence the name) and the page title will be used for the title tag. Great! Unfortunately, in current versions of Typo3 up to 3.6.2, the navigation title in alternative page languages is ignored. Instead, Typo3 shows the default language's navigation title, even in alternative language versions of your page. The fact that there is a backend field called "Navigation Title" in the alternative language page header suggests that this is a bug. I have also seen user reports about it. Until it's fixed we need a workaround.

Update 25.11.04: The bug is not in Typo3 core but in an extension. The extension in question is pk_limitmenutolang version 1.0.0. This extension limits the menus to pages that have a translation in the current language. To fix the extension, login to the backend, go to Extension Manager, select Loaded Extensions from the Menu: drop down box, click on Limits all menues to specified language, select Edit files from the drop down box, click on Edit file next to pi1/class.ux_t3lib_page.php. Find this line,


replace it with this line


and click save. You can now specify navigation titles in alternative languages. You can then use more verbose text in the page title field as it only occurs in the title tag of your pages. We still have to figure out how to get the site title in multiple languages and howto put the page title before the site title.

No Solution

There are two extensions that might offer a soultion: Page Title Changer (mf_pagetitle) by Ruud Kamphuis and bvd_set_page_title by Bart van Doveren. The latter uses the subtitle field instead of the page header for title tags. The subtitle field can be customized to alternative page languages and, unlike navigation title, it is not ignored. This means that it could be used to fix problem number two by putting the long title in subtitle and the short version in title. However, it's not a fix for problem number one. This is where mf_pagetitle could be of help. Using Ruud's extension you can specify a site-wide title in a TypoScript template. Because templates support conditions, you can set different titles for alternative languages. Unfortunately, mf_pagetitle doesn't coexist with bvd_set_page_title.

A Solution

The solution is actually very easy and there is no need for extensions. Remember, that a TypoScript template determines the page body as well as a page's HTML header. Using a template, you can easily set a HTML header tag like <title>:

page.headerData.20 = TEXT
page.headerData.20.field = subtitle // title
page.headerData.20.wrap = <title>Akademie für Fremdsprachen - 
Sprachschule in Berlin:&nbsp;|</title>
This takes the subtitle field or, if undefined, the title field of a page, wraps it with a global site title and emits the title tag. If you put this into your root template and look at the generated HTML source, you will see two title tags: one generated by our template and the default one generated by Typo3. We can suppress the default title tag by adding this to the template.
config.noPageTitle = 1

Second Problem solved. In order to solve the first problem, we employ TypoScript conditions. Which alternative language of a page is shown to the user is usually selected by a URL parameter like http://domain.com/index.php?id=12&L=1 or something similar. I use language aliases like 'en' for English and I named the URL parameter 'lang' so my URLs look like http://domain.com/index.php?id=12&lang=en. We can customize the global site title to each of our alternative languages by using a condition on the URL parameter that selects the page language:

config.noPageTitle = 1
page.headerData.20 = TEXT
page.headerData.20.field = subtitle // title
page.headerData.20.wrap = <title>Akademie für Fremdsprachen - 
Sprachschule in Berlin:&nbsp;|</title>
[globalVar = GP:lang = en]
page.headerData.20.wrap = <title>Akademie für Fremdsprachen - 
Language courses in Berlin:&nbsp;|</title>
[globalVar = GP:lang = fr]
page.headerData.20.wrap = <title>Akademie für Fremdsprachen - 
Cours de langue à Berlin:&nbsp;|</title>

Finally a solution to both problems.

Update 23.11.2004: With horror I realized yesterday that I have two title tags in the generated HTML source. I don't want to know what this did to my rankings in search engines. The problem is that Typo3 still emits a title tag in addition to the one generated by our template. The config.noPageTitle setting only suppresses the inclusion of the page title in the title tag but it doesn't disable the title tag itself because Typo3's title tag contains the value of the config.siteTitle setting. Consequently, you need to set config.siteTitle to an empty string. In the backend, go to the root of your site, click on the Template module and edit the "Sitetitle:" entry. Now, the second title tag is still emitted but at least it's empty. To get rid of the whole tag you need to apply the following patch. The patch suppresses the emission of a title tag if the tag's content would be empty. I submitted it to the Typo3dev mailing list. Let's see what happens.

--- class.tslib_pagegen.php.old Mon Nov 22 15:03:47 2004
+++ class.tslib_pagegen.php     Mon Nov 22 14:56:21 2004
@@ -605,8 +605,10 @@
                        $titleTagContent = $GLOBALS['TSFE']->cObj
array(), $titleTagContent);

-               $GLOBALS['TSFE']->content.='
+               if( strlen( $titleTagContent ) ) {
+                       $GLOBALS['TSFE']->content.='
+               }
        <meta name="generator" content="TYPO3 3.7 CMS" />';

( categories: Typo3 | Webmaster )
Submitted by Anonymous on Fri, 03/09/2007 - 09:12.
Submitted by Anonymous on Fri, 09/08/2006 - 11:00.

That was exactly what I was looking for!

Submitted by Anonymous on Thu, 07/06/2006 - 02:40.

You can set
in Typo3 3.8.1 which will omit the TITLE tag completely.

Submitted by Anonymous on Thu, 11/03/2005 - 18:01.

nice article.

If you want to remove the &nbsp; from the title use noTrimWrap instead of wrap.

Sacha Vorbeck