Drupal 7 で既存のメタ タグを削除または変更するにはどうすればよいですか? drupal 6drupal_set_header
では、またはそのようなことがありましたが、Drupal 7 はそれについて知りません。
追加のモジュールなしでこれを行う方法はありますか? 現在、2 つのメタ ディスクリプション タグがありますが、それは必要ありません。
hook_html_head_alter()を実装して、Drupal7の既存のヘッドタグを変更できます。
また、古い関数の代わりにdrupal_add_html_head()関数とdrupal_add_html_head_link ()関数を使用することもできますdrupal_set_header()
。
メタ タグ モジュールを使用している場合は、hook_metatag_metatags_view_alterを実装できます。
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;
}