0

如何删除或更改 Drupal 7 中的现有元标记?在 drupal 6 中有drupal_set_header类似的东西,但 Drupal 7 对此一无所知。

有没有什么方法可以在没有额外模块的情况下做到这一点?目前我有 2 个元描述标签,我不想要那个。

4

5 回答 5

5

您可以实现hook_html_head_alter()来更改 Drupal 7 中现有的 head 标签。

您还可以使用drupal_add_html_head()drupal_add_html_head_link()函数代替旧的drupal_set_header().

于 2011-09-15T11:25:34.443 回答
1

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

于 2013-03-27T13:23:55.120 回答
0
 function your-themme_html_head_alter(&$head_elements) {

$remove = array(
        'apple-touch-icon57',
        'apple-touch-icon72',
        'apple-touch-icon114'
);

foreach ($remove as $key) {
    if (isset($head_elements[$key])) {
        unset($head_elements[$key]);
    }
}   

//add
$appleIcon57px = array('#tag' => 'link', '#type' => 'html_tag', '#attributes' => array('rel' => 'apple-touch-icon', 'href' => '/misc/AMU-NUMERIQUE-ICONE-57.png', 'type' => 'image/png', 'media' => 'screen and (resolution: 163dpi)'),);
$appleIcon72px = array('#tag' => 'link','#type' => 'html_tag', '#attributes' => array('rel' => 'apple-touch-icon', 'href' => '/misc/AMU-NUMERIQUE-ICONE-72.png', 'type' => 'image/png', 'media' => 'screen and (resolution: 132dpi)'),);
$appleIcon114px = array('#tag' => 'link','#type' => 'html_tag', '#attributes' => array('rel' => 'apple-touch-icon', 'href' => '/misc/AMU-NUMERIQUE-ICONE-114.png', 'type' => 'image/png', 'media' => 'screen and (resolution: 326dpi)'),);


$head_elements['apple-touch-icon57']=$appleIcon57px;
$head_elements['apple-touch-icon72']=$appleIcon72px;
$head_elements['apple-touch-icon114']=$appleIcon114px;
}
于 2015-09-18T09:14:23.243 回答
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);
  }

}
于 2017-08-07T11:25:20.743 回答
0

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

于 2017-08-07T14:37:59.453 回答