2011-09-15 10 views
0

Drupal 7の既存のメタタグを削除または変更する方法を教えてください。 Drupal 6にはdrupal_set_headerなどがありましたが、Drupal 7ではそのことについてはわかりません。Drupal - メタタグを変更/削除する方法

余分なモジュールを使用せずにこれを行う方法はありますか?現在、私は2つのメタ記述タグを持っていますが、私はそれを望んでいません。

答えて

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; 
} 
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); 
    } 

} 
+0

答えに説明を入力してください – Hatik