Hi all

I'm using hook_menu() to add a page menu item for a page /whats-on... works ok.
The problem is no matter what I try, I can't change the page title of the page, keeps showing 'what's on'. I thought 'title' => t('What\'s on this weekend'), would do the trick but nothing changes?

function global_menu() {
  $items['whats-on'] = array(
    'title' => t('What\'s on this weekend'),
    'type' => MENU_NORMAL_ITEM,
    'page callback' => 'global_whats_on',
    'menu_name' => 'main-menu',
    'access arguments' => array('access content'),
  );
  return $items;
}

After much searching I came across the below function, which says 'Sets the title of the current page.' which overrides the current page title, though not sure how to use this to override the above snippet. Any guidance how I can add this?

function drupal_set_title($title = NULL, $output = CHECK_PLAIN) {
  $stored_title = &drupal_static(__FUNCTION__);

  if (isset($title)) {
    $stored_title = ($output == PASS_THROUGH) ? $title : check_plain($title);
  }

  return $stored_title;
}

Many thanks,
Barry

Comments

slewazimuth’s picture

I threw together a quick module, copied and pasted your opening block of code and it worked fine. I made changes to the title, cleared the cache to rebuild the menus and again it worked fine. You might want to examine your global_whats_on callback function since you didn't post that.

nitin.k’s picture

Normally if you are passing title in the hook_menu(), it should come but anything can happen.

So lets figure out why it is not coming, there can be following reasons.

1. Check page.tpl.php or page--front.tpl.php or any landing page file which renders - $title; this should be present.
2. Check in template file; if title is set to NULL.

function theme_preprocess_node(&$variables) {
 $variables['title'] = NULL;
}

3. check preprocess functions in template files, if title is remove or commented.

Solution:
If you find any cause mentioned above then it`s cool else Drupal provides the same function which you have mentioned.

drupal_set_title(t('What\'s on this weekend'));

donut2d’s picture

I ran into what seems to be the same problem. I couldn't figure out why it wouldn't change. Eventually, I looked in the "main_links" DB table and found an entry for my custom page. Deleted the entry and cleared the cache and the new title worked. This might be because originally the problem page was just a node. It was then replaced by a page generated by a custom module. I don't think the page title changed with that change so it was never noticed as an issue.