4.6.x menu.inc menu_get_active_title()
4.7.x menu.inc menu_get_active_title()
5.x menu.inc menu_get_active_title()
6.x menu.inc menu_get_active_title()
7.x menu.inc menu_get_active_title()

Gets the title of the current page, as determined by the active trail.

Related topics

1 call to menu_get_active_title()
drupal_get_title in includes/bootstrap.inc
Gets the title of the current page.
1 string reference to 'menu_get_active_title'
drupal_get_title in includes/bootstrap.inc
Gets the title of the current page.

File

includes/menu.inc, line 2623
API for the Drupal menu system.

Code

function menu_get_active_title() {
  $active_trail = menu_get_active_trail();
  $local_task_title = NULL;

  foreach (array_reverse($active_trail) as $item) {
    // Local task titles are displayed as tabs and therefore should not be
    // repeated as the page title. However, if the local task appears in a
    // top-level menu, it is no longer a "local task" anymore (the front page
    // of the site does not have tabs) so it is better to use the local task
    // title in that case than to fall back on the front page link in the
    // active trail (which is usually "Home" and would not make sense in this
    // context).
    if ((bool) ($item['type'] & MENU_IS_LOCAL_TASK)) {
      // A local task title is being skipped; track it in case it needs to be
      // used later.
      $local_task_title = $item['title'];
    }
    else {
      // This is not a local task, so use it for the page title (unless the
      // conditions described above are met).
      if (isset($local_task_title) && isset($item['href']) && $item['href'] == '<front>') {
        return $local_task_title;
      }
      else {
        return $item['title'];
      }
    }
  }
}

Comments

Dave Reid’s picture

Beware: the return value of this function is interpreted as HTML. If you are printing the result of this function in your code or theme, you must escape them with check_plain or use the correct placeholder in t(). If you don't, users can execute a cross site scripting attack against your site.

// Incorrect:
print menu_get_active_title();

// Correct:
print check_plain(menu_get_active_title());

Edit: fixed typo in function name

BarisW’s picture

Should obviously be
<php? print check_plain(menu_get_active_title()); ?>