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

nicholasthompson’s picture

Status: Patch (to be ported) » Fixed

Restored in DRUPAL-5--2 and DRUPAL-6--2... Will be in the next tagged official release.

Cheers

chif’s picture

Maybe we should have an option to attach site name to a title? Like this (well, not exactly, but just for example)


/**
* 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)) {
    $site_name = ( variable_get('page_title_attach_site_name', FALSE) ? variable_get('site_name', 'Drupal site') : FALSE);
    if ($site_name === FALSE) {
      $stored_title = $title;
    } else {
      $stored_title = $title . variable_get('page_title_site_name_separator', ' | ') . $site_name;
    }
  }
  return $stored_title;
}

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.

nicholasthompson’s picture

This 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...)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.