Those two are somehow very important modules when it comes to SEO, and page_title is closely related to meta tags.

I wonder if any kind of merging with those module, or at least a planned integration might be worth to consider it on the design of this module?

Comments

dave reid’s picture

Page title would likely stay a separate project. Would could maybe add support for page titles from within metatags so a separate joining module is not necessary.

dave reid’s picture

Title: Related modules: page_title, nodewords_pagetitle? » Merge in functionality from page_title and nodewords_pagetitle modules

After some time it almost makes sense to have some type of page title support. See also #948110: Page Title vs Metatags (D7).

nicholasthompson’s picture

I'd be happy to help maintain the Page Title aspect of this module. Makes much more sense to have one well maintained module with a team behind it rather than 2 modules with 2 smaller teams ;)

dave reid’s picture

I just figured out how to get this working in an abstract and reliable fashion for the new code base.

The goods:

/**
 * Set a variable to be altered in metatag_preprocess_html().
 *
 * @see metatag_get_preprocess_variables()
 * @see metatag_preprocess_html()
 * @see metatag_preprocess_maintenance_page()
 */
function metatag_set_preprocess_variable($hook, $variable, $value) {
  $variables = &drupal_static(__FUNCTION__, array());
  $variables[$hook][$variable] = $value;
}

/**
 * Return an array of variables to be altered in preprocess functions.
 *
 * @see metatag_set_preprocess_variable()
 * @see metatag_preprocess_html()
 * @see metatag_preprocess_maintenance_page()
 */
function metatag_get_preprocess_variables($hook) {
  $variables = drupal_static('metatag_set_preprocess_variable', array());
  return isset($variables[$hook]) ? $variables[$hook] : array();
}

/**
 * Implements hook_preprocess_html().
 */
function metatag_preprocess_html(&$variables) {
  foreach (metatag_get_preprocess_variables('html') as $variable => $value) {
    $variables[$variable] = $value;
  }
}

/**
 * Implements hook_preprocess_maintenance_page().
 */
function metatag_preprocess_maintenance_page(&$variables) {
  foreach (metatag_get_preprocess_variables('html') as $variable => $value) {
    $variables[$variable] = $value;
  }
}

And our title tag controller is the following:

class DrupalTitleMetaTag extends DrupalTextMetaTag {
  public function getElement(array $options = array()) {
    $value = check_plain(strip_tags($this->getValue($options)));
    $element = array();
    $element['#attached']['metatag_set_preprocess_variable'][] = array('html', 'head_title', $value);
    $element['#attached']['metatag_set_preprocess_variable'][] = array('html', 'head_array', array('title' => $value));
    return $element;
  }
}

Using the API functions we can alter any variable in hook_preprocess_html() so that we don't need to mess with calling drupal_set_title() and we also do not have to special case title tag handling in metatag_preprocess_html(). Elegant solutions++

So architecturally this is solved, now we just need to have the UI for editing/loading/rendering the tags. :)

BenK’s picture

Subscribing

andypost’s picture

subscribe

dave reid’s picture

Status: Active » Fixed

The unstable1 release already contains page title functionality.

Todd Young’s picture

Pardon my ig'nance but I can't seem to find where you can set the page title of a Panels page in D7... In neither MetaTags nor Page Title modules?

dave reid’s picture

Because we haven't added Panels support yet: #1151938: Panels integration - meta discussion

Status: Fixed » Closed (fixed)

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