You are here

function page_title_get_title in Page Title 5.2

Same name and namespace in other branches
  1. 8.2 page_title.module \page_title_get_title()
  2. 6.2 page_title.module \page_title_get_title()
  3. 6 page_title.module \page_title_get_title()
  4. 7.2 page_title.module \page_title_get_title()
  5. 7 page_title.module \page_title_get_title()

Simple wrapper function to get the currently set title for a page

Return value

string the title for the current page

1 call to page_title_get_title()
page_title_token_values in ./page_title.module
Implementation of hook_token_values().

File

./page_title.module, line 299
Enhanced control over the page title (in the head tag).

Code

function page_title_get_title() {

  // If we're looking at a node or a comment on a node, get the node object from the menu system.
  if (arg(0) == 'node' && is_numeric(arg(1)) || arg(0) == 'comment' && arg(1) == 'reply' && is_numeric(arg(2)) && module_exists('comment')) {
    $nid = arg(0) == 'node' ? arg(1) : arg(2);
    $node = node_load($nid);

    // If the node has a custom page title and the node type is configured to have a custom page title (ie, it's not a leftover from a previous setting), then use it.
    if (!empty($node->page_title) && variable_get('page_title_type_' . $node->type . '_showfield', 0)) {
      $title = $node->page_title;
    }
  }
  elseif (arg(0) == 'user' && is_numeric(arg(1))) {
    if (variable_get('page_title_user_showfield', 0) && ($user_title = page_title_load_title(arg(1), 'user'))) {
      $title = $user_title;
    }
  }
  elseif (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2)) && module_exists('taxonomy')) {
    $term = taxonomy_get_term(arg(2));
    if (variable_get('page_title_vocab_' . $term->vid . '_showfield', 0) && ($term_title = page_title_load_title($term->tid, 'term'))) {
      $title = $term_title;
    }
  }
  elseif (arg(0) == 'forum' && module_exists('forum')) {

    // If there is a number then its a container or forum
    if (is_numeric(arg(1))) {
      $term = taxonomy_get_term(arg(1));
      if (variable_get('page_title_vocab_' . $term->vid . '_showfield', 0) && ($term_title = page_title_load_title($term->tid, 'term'))) {
        $title = $term_title;
      }
    }
    else {
      $title = variable_get('page_title_forum_root_title', '');
    }
  }

  // If nothing above set a title, give the legacy function a chance to act
  if (empty($title)) {
    $title = page_title_set_title();
  }

  // If we still have no title, fall back to the title provided by Drupal Core
  if (empty($title)) {
    $title = drupal_get_title();
  }

  // Give other modules the oppertunity to use hook_page_title_alter() to modify the title.
  foreach (module_implements('page_title_alter') as $module) {
    $function = $module . '_page_title_alter';
    call_user_func_array($function, array(
      &$title,
    ));
  }

  // Return the title in a safe form (allow no tags (such as emphasised or strong tags) and entity encode)
  return filter_xss($title, array());
}