Drupal - 如何更改/删除元标记

时间:2011-09-15 10:53:41

标签: drupal header drupal-7 meta-tags head

如何删除或更改Drupal 7中的现有元标记?在drupal 6中有drupal_set_header或类似的东西,但是Drupal 7并不知道这一点。

如果没有额外的模块,我有什么方法可以做到这一点?目前我有2个元描述标签,我不希望这样。

5 个答案:

答案 0 :(得分:5)

您可以实施hook_html_head_alter()来更改Drupal 7中的现有头标记。

此外,您可以使用drupal_add_html_head()drupal_add_html_head_link()功能代替旧的drupal_set_header()

答案 1 :(得分:1)

如果您使用的是元标记模块,则可以实施hook_metatag_metatags_view_alter

答案 2 :(得分:0)

QTextEdit

答案 3 :(得分:0)

You can implement hook_menu() to add head tags in Drupal 7.

/**
 * Implements hook_menu().
 * @return array
 */
function module-name_menu() {
  $items['add-metatags'] = array(
    'page callback' => 'custom_metatags',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

  return $items;
}

function custom_metatags() {

  $html_head = array(
    'description' => array(
      '#tag' => 'meta',
      '#attributes' => array(
        'name' => 'description',
        'content' => 'Enter your meta description here.',
      ),
    ),
    'keywords' => array(
      '#tag' => 'meta',
      '#attributes' => array(
        'name' => 'keywords',
        'content' => 'Enter your meta keywords here.',
      ),
    ),
  );
  foreach ($html_head as $key => $data) {
    drupal_add_html_head($data, $key);
  }

}

答案 4 :(得分:0)

考虑通过GUI安装https://www.drupal.org/project/metatag来控制页面元标记。