Closed (fixed)
Project:
Page Title
Version:
5.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
8 Apr 2009 at 12:20 UTC
Updated:
6 May 2009 at 08:20 UTC
If like me you write your own modules that provide page views, there is currently no way (there was) to set the meta title from inside of your module. There was a function in the version 1 branch called "page_title_set_title", this allowed module developers to set meta page titles from inside the module, same way that you can use drupal_set_title:
here is a re-worked code from the latest module, hopefully this can be integrated into the next version. I am pasting the code here for my own reference.
STEP 1:
edit page_title_page_get_title function and replace:
//If pattern is emtpy (either if the type is not overridable or simply not set) fallback to the default pattern
if (empty($title)) {
$title = variable_get('page_title_default', '[page-title] | [site-name]');
}
to this:
//If pattern is emtpy (either if the type is not overridable or simply not set) fallback to the default pattern
if (empty($title)) {
$title = (page_title_set_title()) ? page_title_set_title() : variable_get('page_title_default', '[page-title] | [site-name]');
$title = strip_tags($title);
}
STEP 2:
add the page_title_set_title function:
/**
* Sets or retrieves the page title of the current page.
*
* @param $title
* string The page title to set.
* @return
* string The current page's title.
*/
function page_title_set_title($title = NULL) {
static $stored_title;
if (isset($title)) {
$stored_title = $title;
}
return $stored_title;
}
Comments
Comment #1
nicholasthompsonRestored in DRUPAL-5--2 and DRUPAL-6--2... Will be in the next tagged official release.
Cheers
Comment #2
chif commentedMaybe we should have an option to attach site name to a title? Like this (well, not exactly, but just for example)
So one can have titles like "My module title :: My site name" without calling
page_title_set_title('My module title' . ' :: ' . variable_get('site_name', 'Drupal site') )on each page.Comment #3
nicholasthompsonThis is not necessary as it's already available in the module settings. All you'd need to do is set the default page title tokens to:
[title] :: [site-name](you'd need to check the site name token...)