4

Can the Window/Browser title be set separately from the page title (which is displayed in an <h1>)?

I'd like to be able to do this in the most direct way possible from code, not using extra modules or configurations (unless that is the best route).

For example, I often use drupal_set_title() on a page definition. I'd love to call a similar function right next to this to set a slightly different version as the window title.

6

The title set with drupal_set_title() is both the page title, and the browser window title.
If you are looking for a module that can change tHE window title, you can look at Page Title.

If you want to be able to do it from A CUSTOM module, you can implement hook_preprocess_page(&$variables) to modify the content of $variables['head_title'], which contains a modified version of the page title to use in the <title> tag.

function mymodule_preprocess_page(&$variables) {
  $variables['head_title'] = t("The new HTML title.");
}
  • kia, I cannot find the reference to hook_preprocess_page on the Hooks page on the main Drupal site. – Lester Peabody Aug 2 '11 at 16:04
  • @Lester Peabody The documentation page for all those preprocess hooks is only one: hook_preprocess_HOOK(). – kiamlaluno Aug 2 '11 at 16:08
  • So say if I had a separate template for a user page, via page--user.tpl.php, would the hook for that be MODULE_preprocess_page_user(&$variables)? – Lester Peabody Aug 2 '11 at 16:28
  • @Lester Peabody As far as I know, no. The template normally used is page.tpl.php; page--user.tpl.php is just a suggestion, and for the suggestions there isn't a specific hook. – kiamlaluno Aug 2 '11 at 16:32
3

You may want to checkout the Page Title project http://drupal.org/project/page_title

Allows you to customize the page title on a per content or per node basis.

Some details from the module's project page:

The word "title" is a bit overloaded. Every piece of content in Drupal has a title, and so does every page. The page title is the one found in the HTML head inside the tag. It is also used on SERPs (Search Engine Result Pages) and can greatly enhance your websites SEO (Search Engine Optimization).

This module gives you granular control over the page title. You can specify patterns for how the title should be structured and, on content creation pages, specify the page title separately to the content's title.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.