Saturday 9 October 2010

Changing Drupal web page $head_title value.

I think I,ve had asked myself this topic quite a lot of times, how to change this web pages variable $head_title to adjust to your sites needs.
So, answer is easy actually, because you have
beautiful  theming function phptemplate_preprocess_page();

So here it..
comes simple and easy code:

function phptemplate_preprocess_page(&$vars) {
$path = $_GET['q'];
$path = drupal_get_path_alias($path, $path_language = '');
$patharray = explode("/", $path);
if ($patharray[0] == 'your-page-path') {// you might need to adjust it to you path settings might be [1] orr... [n]
$vars['head_title'] = 'My cool site';
}
else {
$new_title = array($vars['title'], $vars['site_name']);
$vars['head_title'] = implode(' | ', $new_title)
}
}


To test it just put "print $head_title;" somewhere on your page and see how it works.

No comments:

Post a Comment